【发布时间】:2015-06-13 00:38:40
【问题描述】:
我希望敌人在 1-5 秒之间随机生成,但是当我在游戏中应用脚本时,游戏中充斥着大量敌人,并且它不断地不断生成敌人!
using UnityEngine; using System.Collections;
public class Game_Control : MonoBehaviour {
private bool Spawn1=true;
public GameObject Spearman;
private float STimer;
void Start () {
STimer = Random.Range(1f,5f);
}
void Update () {
if (Spawn1 = true) {
Instantiate (Spearman, transform.position, transform.rotation);
StartCoroutine (Timer ());
}
}
IEnumerator Timer() {
Spawn1 = false;
yield return new WaitForSeconds (STimer);
Spawn1=true;
}
}
【问题讨论】:
标签: unity3d