Hello This is Mahsa ,
I have a complicated question , I am Collecting some object with player trigger , collectable objects are close to each other, I want the player even trigger with multiple objects collect one of them , I did this with bool and it works perfectly the problem is when I trigger for example object 1 and then without exiting from object 1 , turn to collect object 2 it does not OnTriggerEnter
object 2 , can anyone help me ? if it’s not clear ask me to explain more
here’s code for just trigger once
public bool isTriggered = false;
void OnTriggerEnter(Collider other)
{
if (isTriggered == false)
{
var collectable = other.GetComponent<Collectable>();
if(!collectable) return;
Debug.Log("Enter: " + collectable.name);
}
isTriggered = true;
}
void OnTriggerStay(Collider other)
{
var collectable = other.GetComponent<Collectable>();
if(!collectable) return;
Debug.Log("Stay : " + collectable.name);
}
void OnTriggerExit(Collider other)
{
var collectable = other.GetComponent<Collectable>();
if(!collectable) return;
Debug.Log("Exit : " + collectable.name);
isTriggered = false;
}