I am making text appear then dissapear after the time in the float variable called waitseconds, however whenever i test this it never executes after the waitforseconds, im not sure why this is happening, the Correct gameobject is setting active but then not deactivating after the yield.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Answer : MonoBehaviour
{
public bool answer;
public GameObject back;
public GameObject Player;
public GameObject Correct;
public GameObject incorrect;
public float waitseconds = 0.5f;
void OnTriggerEnter(Collider other)
{
if (answer == true)
{
StartCoroutine("Correctanswer");
Destroy(this.gameObject);
Destroy(back.gameObject);
Debug.Log("destroy");
PlayerMovement.Score += 500;
}
if (answer == false)
{
PlayerMovement.livesleft -= 1;
}
}
void Update()
{
if (PlayerMovement.livesleft == 0)
{
SceneManager.LoadScene("Fail");
}
}
private IEnumerator Correctanswer()
{
Correct.gameObject.SetActive(true);
Debug.Log("aftertrue");
yield return new WaitForSeconds(waitseconds);
Correct.SetActive(false);
Debug.Log("afteryield");
}
}