Search Unity

Pause animation on collide??

Discussion in 'Scripting' started by Quist, Sep 22, 2014.

  1. Quist

    Quist

    Joined:
    Feb 25, 2014
    Posts:
    284
    So i have a door script which plays the DoorOpen animation when left click is pressed.

    What i want to happen: If the player touches the door before it reaches its final open destination it should stop until he move from its path.

    Currently the door kinda goes "nocolliding" when it enters the animation?
    The collider is still there and i cant go through it normally, but when the animator plays the door just goes through the player. How do i make it so it stops on collision with the player and doesnt go nocollide?

    Code:

    Code (JavaScript):
    1.  
    2. #pragma strict
    3.  
    4. var theDoor : Transform;
    5. private var drawGUI = false;
    6. private var doorIsClosed= true;
    7.  
    8. function Update ()
    9. {
    10.     if (drawGUI == true && Input.GetKeyDown("mouse 0"))
    11.     {
    12.         changeDoorState();
    13.     }
    14. }
    15.  
    16. function OnTriggerEnter (theCollider : Collider)
    17. {
    18.     if (theCollider.tag == "Player")
    19.     {
    20.         drawGUI = true;
    21.     }
    22. }
    23.  
    24. function OnTriggerExit (theCollider : Collider)
    25. {
    26.     if (theCollider.tag == "Player")
    27.     {
    28.         drawGUI = false;
    29.     }
    30. }
    31.  
    32. function OnGUI ()
    33. {
    34.     if (drawGUI == true)
    35.     {
    36.         GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Left click to open");
    37.     }
    38. }
    39.  
    40. function changeDoorState ()
    41. {
    42.     if (doorIsClosed == true)
    43.     {
    44.         theDoor.animation.CrossFade("DoorOpen");
    45.         //theChest.audio.PlayOneShot();
    46.         doorIsClosed = false;
    47.         yield WaitForSeconds(3);
    48.         theDoor.animation.CrossFade("DoorClose");
    49.         //theChest.audio.PlayOneShot();
    50.         doorIsClosed = true;
    51.     }
    52. }
    53.