Hello there, I’m new at unity and I’m having troubles with the scripts. I know this should have a simple solution but I couldn’t find a solution that fits to my problem.
I have a GameObjects that actives a trigger and active an animation when the player reach its collider, that works fine, the problem is that I have another object with the same script because I want it to do the same. Those two objects share the animator and the script because they do basicaly the same, the problem is that when the player reach the first collider, both objects starts its animation. I need a lot of this objects and I don’t want to do a script or an animator for every single one, but I don’t undertand why the collider of one objects triggers the animation of the other object.
They are not related in the hierarchy and I’m not using static variables, please help me to solve this.
This is the code:
//---------------------------------------------------------------------------------
TriggerDialogos Trigger;
Animator Anim;
public GameObject CalzonSiguiente;
void Start()
{
Anim = GetComponent();
Trigger = GetComponent();
}
void OnTriggerEnter2D(Collider2D other)
{
Trigger.ActivarDialogo();
Anim.SetTrigger(“Desaparecer”);
if (CalzonSiguiente != null)
{
CalzonSiguiente.SetActive(true);
}
}