Hi All,
I was messing around for a bit and i was just wondering how you would make it so that when an object enters a trigger it has to wait there for five seconds or so for it to activate.
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "L_O_S") { Debug.Log("Object found"); Destroy(gameObject); } }
I have looked at waitforseconds, invoke and more to try and achieve this but it all just activates it a couple of seconds after you enter the trigger, not making you wait in the trigger for those seconds.
I think you can use Time.deltaTime, for example:
bool isTriggered;
float waitTime = 5f;
void Update () {
if (isTriggered == true) {waitTime -= Time.deltaTime;}
if (isTriggered == true && waitTime <= 0f) {Debug.Log(“Object found”); Destroy(GameObject.FindGameObjectWithTag(“L_O_S”));}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == “L_O_S”)
{
isTriggered = true;
}
}