i am having this error when i try to run my coroutine
Coroutine couldn’t be started because the the game object ‘Player’ is inactive!
why is this happening? thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class PlayerDeath : MonoBehaviour
{
GetAudioSource audioSFX;
SceneLoader sceneLoader;
[SerializeField] GameObject ball;
[SerializeField] ParticleSystem deathVFX;
[SerializeField] Image loseScreen;
[SerializeField] Transform playerUI;
[SerializeField] float delayToShowScreen = 0.5f;
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
audioSFX = FindObjectOfType<GetAudioSource>(); // find this object and reference it whenever the variable is used.
sceneLoader = FindObjectOfType<SceneLoader>();
}
// Update is called once per frame
void Update()
{
}
public void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "DeathTrigger")
{
PlayerDying();
}
}
private void OnDestroy()
{
StartCoroutine(DisplayScreen());
}
public void PlayerDying()
{
deathVFX.transform.parent = null; // deathVFX loses it's child relationship with player parent
deathVFX.Play();
audioSFX.audioSource.PlayOneShot(audioSFX.deathSFX, 1.5f);
Destroy(ball);
Instantiate(loseScreen, playerUI); // instantiates loseScreen below UI game object
}
public IEnumerator DisplayScreen() // IEnumerator used to give a delay to some action also called coroutine
{
yield return new WaitForSeconds(delayToShowScreen); // gives a delay time
Debug.Log(loseScreen);
Instantiate(loseScreen, playerUI); // instantiates loseScreen below UI game object
}
private void ReloadScene()
{
sceneLoader.ReloadScene();
}
}