I’m trying to Enter a trigger call a function which sets a bool to true then wait for a second or two and then set the bool to false and also Debug.Log to tell me it worked. The code I currently have doesn’t give me any errors, but it is only setting the bool to true and destroying the gameObject from there it doesn’t seem to do anything. If you can help solve my issue it would be greatly appreciated!
My code is this currently:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DoubleNuggets : MonoBehaviour
{
private GameObject doubler;
private void Start()
{
doubler = GameObject.FindWithTag("coinmanager");
}
IEnumerator OnTriggerEnter(Collider collision)
{
doubler.GetComponent<CoinsManager>().shouldDouble = true;
Destroy(gameObject);
yield return new WaitForSeconds(1);
doubler.GetComponent<CoinsManager>().shouldDouble = false;
Debug.Log("Worked");
}
}