public void AnimatorAboutToSpawn() { if (_foodSpawnQueue.Count == 0) { return; } FoodSpawnDefinition nextFood = _foodSpawnQueue.Peek(); SetIndicatorColor(nextFood.color); _audioSource.PlayOneShot(_spawningSounds.GetRandomClip()); }
public void QueueSpawn(int count) { // dont let queue get too big if (_foodSpawnQueue.Count > 100) { return; } for (int i = 0; i < count; i++) { FoodSpawnDefinition spawn = new FoodSpawnDefinition(); spawn.color = Random.ColorHSV(0f, 1f, 0.25f, 0.8f, 1f, 1f); _foodSpawnQueue.Enqueue(spawn); } }
/// <summary> /// Called by the animator when we are ready to spawn food /// </summary> public void AnimatorSpawnFood() { if (_foodSpawnQueue.Count == 0 || !isOpen || !_isFiring) { return; } UpdateAnimatorSpeed(); FoodSpawnDefinition food = _foodSpawnQueue.Dequeue(); FoodObject newFood = Instantiate(foodPrefab.gameObject).GetComponent <FoodObject>(); newFood.transform.position = spawnPoint.position; newFood.GetComponent <Rigidbody>().AddForce(spawnPoint.forward * spawnForce * (Random.value + 1f), ForceMode.Impulse); newFood.spawner = this; newFood.SetColor(food.color); foodInScene.Add(newFood); }