Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Animation through script?

Discussion in 'Animation' started by LABoy, Jun 20, 2014.

  1. LABoy

    LABoy

    Joined:
    Jun 20, 2014
    Posts:
    3
    Hello, I'm trying to make a game where I have a block going up and down like an elevator. I have animations set and the script should work, but it's not. It says that the animation is not found. I'm not using the animator, but the animation. Under animation in the inspector I have all the animations in the array, but it's still not finding the animation. Please help. My script will be below.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Elevator : MonoBehaviour {
    5.     private bool isGrounded;
    6.     public int delayTime;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.         isGrounded = true;
    11.         StartCoroutine(Go ());
    12.    
    13.     }
    14.  
    15.     IEnumerator Go()
    16.     {
    17.         while (true)
    18.         {
    19.             if(isGrounded == true)
    20.             {
    21.                 animation.Play ("ElevatorAnim");
    22.                 isGrounded = false;
    23.                 yield return new WaitForSeconds (3f);
    24.             }
    25.             if(isGrounded == false)
    26.             {
    27.                 animation.Play ("Elevator_Down");
    28.                 isGrounded = true;
    29.                 yield return new WaitForSeconds (3f);
    30.             }
    31.         }
    32.     }
    33. }
     
  2. LABoy

    LABoy

    Joined:
    Jun 20, 2014
    Posts:
    3
    Also, try to make your reply easy to understand. I'm new to unity (The scripting part, I've had it for a while and just messed with the premade scripts) and I am only thirteen.