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. Dismiss Notice

Need help with simple Door trigger

Discussion in 'Scripting' started by Jeff79, Sep 23, 2015.

  1. Jeff79

    Jeff79

    Joined:
    Sep 13, 2015
    Posts:
    4
    I'm trying to make a door can be trigger by a power switch. But it keeps playing the animation at the start of the level.

    This is the script for the door.

    public Animation anim;

    void Start()
    {
    anim = GetComponent<Animation> ();

    }

    void Update()
    {
    if(GameVariable.electCount > 1)
    {


    anim.Play("FinalDoor");
    }
    }
    }

    This is the script for the trigger.


    //player trigger final door
    void OnTriggerEnter (Collider other)
    {
    if (other.tag == "Player")
    {
    GameVariable.electCount +=1;
    }

    }
    }


    This is a script for variable

    public static class GameVariable {
    public static int electCount;
    }
     
  2. Michael-N3rkmind

    Michael-N3rkmind

    Joined:
    Aug 16, 2015
    Posts:
    24
    On your Door object, look for "Animation" Component and uncheck "Play automatically"

    Hope this helps

    ~N3rk