using UnityEngine;
public class Despawner : MonoBehaviour {
public float waitTime = 2.0f;
float timer;
void Update()
{
timer += Time.deltaTime;
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "Despawner")
{
if (timer > waitTime)
{
Destroy(gameObject);
timer = 0f;
}
}
}
I am trying to destroy an object after 1 second when a collision happens with another object but it instantly gets destroyed, not after the wait time.
Destroy(gameObject, 5);
– AshGetemThank You!!!
– _Ima_Banana