Search Unity

newbie animation question

Discussion in 'Scripting' started by peptoabysmal, Nov 30, 2007.

  1. peptoabysmal

    peptoabysmal

    Joined:
    Oct 4, 2007
    Posts:
    33
    Hi,

    Heres some background on the problem.

    I have the earth tutorial from Cheetah 3D as my game object. It is a child of an empty game object to keep it from moving when the animation starts.

    I have another empty game object that has a GUI script.
    Just trying to make a play button that plays the animation.

    Anyway, when I click the play button, nothing happens.
    I don't think the problem is with the GUI part of the code, but rather how I'm accessing the animation object.

    TIA

    Here's the code:
    Code (csharp):
    1. var hSliderValue : float = 0.0;
    2. var showControls = true;
    3. var earth : GameObject;
    4.  
    5. function OnGUI () {
    6.     if(showControls){
    7.         showControls = GUI.Toggle (Rect (25,100, 120, 30), showControls, "Hide Controls");
    8.         hSliderValue = GUI.HorizontalSlider (Rect (25, 25, 200, 30), hSliderValue, 0.0, 100.0);
    9.         var line : String;
    10.         line = "";
    11.         line += hSliderValue;
    12.         GUI.Label (Rect (25, 40, 100, 30), line);
    13.         if(GUI.Button(Rect(50,60,50,30),"Play")){
    14.             print(Time.frameCount);
    15.             earth.animation.Play("idle");
    16.         }
    17.         if(GUI.Button(Rect(100,60,50,30),"Stop")){
    18.             print(Time.frameCount);
    19.             earth.animation.Stop();
    20.         }
    21.     }else{
    22.         showControls = GUI.Toggle (Rect (25,25, 120, 30), showControls, "Show Controls");
    23.     }
    24. }
     
  2. peptoabysmal

    peptoabysmal

    Joined:
    Oct 4, 2007
    Posts:
    33
    After a good night's sleep I got it figured out.


    here is the code that worked:
    Code (csharp):
    1. var hSliderValue : float = 0.0;
    2. var showControls = true;
    3. var earth : GameObject;
    4.  
    5. function OnGUI () {
    6.     if(showControls){
    7.         showControls = GUI.Toggle (Rect (25,100, 120, 30), showControls, "Hide Controls");
    8.         hSliderValue = GUI.HorizontalSlider (Rect (25, 25, 200, 30), hSliderValue, 0.0, 100.0);
    9.         var line : String;
    10.         line = "";
    11.         line += hSliderValue;
    12.         GUI.Label (Rect (25, 40, 100, 30), line);
    13.         if(GUI.Button(Rect(50,60,50,30),"Play")){
    14.             print(Time.frameCount);
    15.             earth.animation.Play();
    16.         }
    17.         if(GUI.Button(Rect(100,60,50,30),"Stop")){
    18.             print(Time.frameCount);
    19.             earth.animation.Stop();
    20.         }
    21.     }else{
    22.         showControls = GUI.Toggle (Rect (25,25, 120, 30), showControls, "Show Controls");
    23.     }
    24. }