I am trying to build a scene where I have multiple game objects and each of them has their own animation that is triggered separately upon collision with the main collider / player. So far it is working well with one game object. Once I try adding several ones, all animations will start, although it is only entering the trigger zone of say gameobject1.
Any ideas? My script is below.
Thank you!
sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Switch2 : MonoBehaviour
{
public GameObject ObjectToEnable;
void Start()
{
ObjectToEnable.SetActive(false);
}
void OnTriggerEnter(Collider other)
{
ObjectToEnable.SetActive(true);
}
}
I’m not sure if I understand your logic behind this pattern correctly, but; maybe you could implement this so, that you have OnTriggerEnter in your objects, and when your player enters a trigger, it will start whatever it needs to start in that specific object instance.
i.e. something like this:
private void OnTriggerEnter(Collider other)
{
// If it's the player (detect with tag you have set.)
if (other.tag == "Player")
{
// Flip a trigger in this Animator instance to start animation playback.
animator.SetTrigger("reactionAnim");
}
}
animator would be of type Animator and something you assign automatically with code or use Inspector to do it.