【发布时间】:2017-04-26 11:52:11
【问题描述】:
我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Enemy : MonoBehaviour {
public GameObject deathEffect;
public float health = 4f;
public static int EnemiesAlive = 0;
public int loadToScene;
void Start ()
{
EnemiesAlive++;
}
void OnCollisionEnter2D (Collision2D colInfo)
{
if (colInfo.relativeVelocity.magnitude > health)
{
Die();
}
}
void Die ()
{
Instantiate(deathEffect, transform.position, Quaternion.identity);
EnemiesAlive--;
if (EnemiesAlive <= 0)
{
Debug.Log ("LEVEL WON!");
StartCoroutine (delay()); //delay here
loadToScene = 1;
SceneManager.LoadScene (loadToScene);
}
Destroy(gameObject);
}
IEnumerator delay ()
{
yield return new WaitForSeconds(2f);
Debug.Log ("Coroutine started?");
}
}
代码是关于当敌人数量小于或等于零时改变场景。鉴于条件“EnemiesAlive
"Debug.Log ("LEVEL WON!");"已读取但“Debug.Log ("Coroutine started?");"没有运行。
【问题讨论】:
-
您不应该在标题中放置标签。网站上的标签系统足以显示您正在使用的平台