Opening Mrt Gate with Animator

The new MECANIM can be used to control animations. I have two set of animator setup.

The LeftGate ani contains leftDoorOpen and leftDoorClose animations similarly, the RightGate ani contains rightDoorClose and rightDoorOpen animations


In the animator view, we can see the two states and they are connected.


A bool parameter call Open is setup to control the transitions between the two animation states.


 
 

Now the script to control the opening of the door when the trigger is active.

using UnityEngine;
using System.Collections;

public class TapCard : MonoBehaviour {

    public Animator leftGate;
    public Animator rightGate;
    public AudioClip beep;
    AudioSource audio;

    // Use this for initialization
    void Start () {
        audio = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update () {

    }

    void OnTriggerEnter(Collider other) 
    {
        if (other.gameObject.CompareTag ("MrtCard"))
        {
            audio.PlayOneShot(beep, 0.7F);

            leftGate.SetBool ("Open", true);
            rightGate.SetBool ("Open", true);
        }
    }
}