Like the title says, is there a way to deactivate an object randomly between a given time? I know there’s something like OnBecameVisible but is there an OnBecameInvisible or something like that?
EDIT
After some messing around i managed to do something but is there a way to fade the audio out from the audio source I attached (not referenced in script).
Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChaseDeactivate : MonoBehaviour
{
[SerializeField]
private float delayBeforeLoad;
[SerializeField]
public GameObject killerObj;
private float timeElapsed;
void Start()
{
delayBeforeLoad = Random.Range(15.0f, 45.0f);
}
private void Update()
{
timeElapsed += Time.deltaTime;
if (timeElapsed > delayBeforeLoad)
{
Destroy(killerObj);
}
}
}