Search Unity

how can I control a animation by a script

Discussion in 'Scripting' started by alexander, Mar 28, 2008.

  1. alexander

    alexander

    Joined:
    Mar 28, 2008
    Posts:
    180
    Hi,
    I want to trigger a game object by a script.
    In fact I've got a game object with BoxCollider, Rigidbody and Configurable Joint like it was described in the 2D-Game-Tutorial.
    Also I've allocated an animation to this GameObject.

    My FPC has got a BoxCollider too and I thought, when the FPC-Box hits the GameObject-Box the animation will be played - and when the FPC leaves the other Box, the animation will reset or play another animation.

    But how to script this?

    That's my try but that's my first script...
    Code (csharp):
    1. var animationRoot : Animation;
    2.  
    3. function OnTriggerEnter (col : Collider)
    4. {
    5.     var controller : FirstPersonController = col.GetComponent(FirstPersonController);
    6.     if (controller != null)
    7.     {
    8.         Animation.clip;
    9.         animationRoot.wrapMode = WrapMode.Once;
    10.     }
    11. }
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Good idea. Go do it :)
     
  3. alexander

    alexander

    Joined:
    Mar 28, 2008
    Posts:
    180
    I frat with the script reference and by now my code is still not working:

    Code (csharp):
    1. var animationRoot : Animation;
    2.  
    3.  
    4. function OnCollisionEnter (col : Collision)
    5. {
    6. animation.Play("HaustuerOpener");
    7.     //animationRoot.wrapMode = WrapMode.Once;
    8. }
    9.  
    10.  
    The script is attached by the "Haustuer".