Search code examples
unity-game-enginegame-developmentvirtual-reality

How do you play animation in unity when you walk through a trigger


I’m making a horror vr game in unity with the ovr player controller and I’m trying to figure out how to make an animation I made in blender play behind me when ever I walk into a certain box trigger.


Solution

  • You could use something along the lines:

    [SerializeField] private GameObject player;
    [SerializeField] private Animation animation;
    
    private void OnTriggerEnter(Collision other)
    {
        if (other.gameObject == player)
            animation.Play();
    }
    

    The player and animation fields need to be initialized from the inspector.