I have a trigger that plays an animation but when i switch scene and i come back to the original scene, the animation plays again. I want to remember actioned triggers in order to play triggers once per scene. How can I do that?
The GlobalScript
public class GlobalScript : MonoBehaviour
{
public static GlobalScript Instance;
public Animator ani;
void Awake ()
{
if (Instance == null)
{
DontDestroyOnLoad(gameObject);
Instance = this;
}
else if (Instance != this)
{
Destroy (gameObject);
}
}
}
The current script (Running every time i load the scene)
public Animator ani;
public AudioClip sound;
public GameObject text;
private int seconds = 2;
//var delay = 2.0; //This implies a delay of 2 seconds.
// public void SavePlayer(){
// GlobalScript.Instance.ani= ani;
// }
// Use this for initialization
void Start () {
ani= GlobalScript.Instance.ani;
ani.enabled = false;
text.SetActive (false);
}
void OnTriggerEnter(Collider other){
AudioSource.PlayClipAtPoint (sound, transform.position);
ani.enabled = true;
text.SetActive (true);
Destroy (gameObject);
Destroy (text,3);
//text.SetActive (true);
//StartCoroutine(Die());
}
//And function itself
IEnumerator Die(){
//play your sound
text.SetActive(true);
yield return new WaitForSeconds(2); //waits 3 seconds
Destroy(gameObject); //this will work after 3 seconds.
}
}