Search Unity

need help to set speed and time in animation2D

Discussion in 'Animation' started by ashkanis, Feb 17, 2014.

  1. ashkanis

    ashkanis

    Joined:
    Sep 22, 2012
    Posts:
    21
    Hello Everybody

    i have a null refrence exception when i try to set the speed prgrammatically of a 2d animation

    the animator and animation component are set to the tutrle object:

    $Capture d’écran (2).png

    the code looks like this in c#

    Code (csharp):
    1.  
    2. public class TurtleScript : BaseSceneElement {
    3.     Animation ani;
    4.     // Use this for initialization
    5.     void Awake () {
    6.         ani=transform.root.GetComponent<Animation>();
    7.         ani["turtanim"].speed=1f; //Null Reference Exception
    8.     }
    9.    
    10.     // Update is called once per frame
    11.     void Update () {
    12.         Scroll ();
    13.         Debug.Log ("sprite turtle:"+ani["turtanim"].time);
    14.     }
    15. }
    16.  
    cant figure why i have this null pointer. Could somebody be kind enough to help me?

    also, i cannot edit an existing animation, everytime i want to drag an animation in the animation window i cant
    all buttons from the animation window want me to create a new animation not edit an existing one


    many thanks

    Ashkanis
     

    Attached Files: