public void arrive(FlyingDoge theDoge) { theDoge.canMove = false; theDoge.reset(); dogePool.Enqueue(theDoge.gameObject); dogeCount--; }
// Start is called before the first frame update void Start() { Vector3 initPos = new Vector3(RightBound, upperBound, 0); for (int i = 0; i < dogeCountLimit; i++) { GameObject newBornDogeObject = Instantiate(doge, initPos, Quaternion.identity); FlyingDoge theDoge = newBornDogeObject.GetComponent <FlyingDoge>(); theDoge.generator = this; dogePool.Enqueue(newBornDogeObject); } StartCoroutine(generateDoge()); }
private IEnumerator generateDoge() { while (true) { // gen if (dogeCount < dogeCountLimit && Random.Range(0f, 1f) < prob) { FlyingDoge nextDoge = dogePool.Dequeue().GetComponent <FlyingDoge>(); nextDoge.canMove = true; nextDoge.reset(); nextDoge.startFly(); dogeCount++; } yield return(new WaitForSeconds(coolDown)); } }