//取得可用的小雞物件 private GameObject GetChickenObject() { GameObject result; if (GetIdleChicken != null) //若事件內容不為空 { IdleChickenEventArgs _eventArgs = new IdleChickenEventArgs(); GetIdleChicken.Invoke(this, _eventArgs); if (_eventArgs.idleChickenObject != null) //有取得閒置中的小雞物件 { result = _eventArgs.idleChickenObject; return(result); } } result = Instantiate(chickenPrefab, parentHolder); //找不到閒置中的小雞時, 創建一隻新的 ChickenMove _moving = result.GetComponent <ChickenMove>(); //取得腳本 _moving.Initialize(this); //小雞行為初始化 return(result); }
//產生小雞 private IEnumerator Cor_Born(ChickenInfo info) { for (int i = 0; i < info.lineCount; i++) { GameObject _go = GetChickenObject(); ChickenMove _moving = _go.GetComponent <ChickenMove>(); //取得腳本 float randomScale = Random.Range(info.randomScaleRange.x, info.randomScaleRange.y); //尺寸隨機 _moving.Move(randomScale, info.bornPos, info.targetPos, info.duration); //開始移動程序 yield return(new WaitForSeconds(info.lineSpacingTime)); //間隔時間差 } }