Why the StartCoroutine(GameOver()); don’t work
my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine;
public class P_Collide : MonoBehaviour {
public int Moneys;
public GameObject MoneyUI;
public static int health = 3;
public AudioClip CollectMoney;
public AudioClip pain;
// Update is called once per frame
void Update () {
if (health <= 0)
{
StartCoroutine(GameOver());
}
}
private void OnTriggerEnter2D(Collider2D trig)
{
if (trig.gameObject.tag == "Money")
{
GetComponent<AudioSource>().PlayOneShot(CollectMoney, 0.5f);
Moneys++;
MoneyUI.GetComponent<Text>().text = (Moneys.ToString());
Destroy(trig.gameObject);
}
if (trig.gameObject.tag == "log")
{
TakeDamage();
}
}
void TakeDamage()
{
GetComponent<AudioSource>().PlayOneShot(pain, 0.5f);
health--;
}
IEnumerable GameOver ()
{
yield return new WaitForSeconds(1.0f);
SceneManager.LoadScene("Main");
yield return null;
}