this is my script I need help to add a time delay between the setActive(true) and SetActive(false)
public class jumpscare : MonoBehaviour {
public GameObject cake;
void OnTriggerEnter (Collider other)
{
cake.SetActive(true);
}
private void OnTriggerExit(Collider other)
{
cake.SetActive(false);
}
},
Check what is coroutines in unity: Unity - Manual: Coroutines. It`s the easiest way to make delay.
Example:
private void OnTriggerEnter(Collider other)
{
cake.SetActive(true);
StartCoroutine(CakeDelay(2f));
}
private IEnumerator CakeDelay(float delay)
{
yield return new WaitForSecondsRealtime(delay);
cake.SetActive(false);
}
In ur case cake is becoming active on trigger enter, and non active on trigger exit.