Question by
Haeder2132 · Aug 11, 2017 at 06:51 AM ·
sceneienumeratorstartcoroutinegameover
Why the StartCoroutine(GameOver()); don't work
Why the StartCoroutine(GameOver()); don't work my code using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine; using System;
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)
{
}
}
private void OnTriggerEnter2D(Collider2D trig)
{
if (trig.gameObject.tag == "Money")
{
StartCoroutine(GameOver());
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;
}
}
Comment
Your answer
Follow this Question
Related Questions
Why the StartCoroutine(GameOver()); don't work 3 Answers
Flash Image once 1 Answer
count how many times a scene is loaded 1 Answer
wait WWW to finish download with yield does not work 0 Answers