public static void Play(string key, int index = -1, bool once = false, Action forward = null) { if (!AudioController.instance.ContainsKey(key)) { return; } AudioSource audio = AudioController.instance [key].audio; if (once && audio.isPlaying) { return; } if (index > -1) { audio.clip = AudioController.clips[index]; } audio.Play(); if (forward != null) { AudioController.wait = audio.gameObject.DoSomethingLater(forward, audio.clip.length); } }
void Start() { float startFrom = this.startFrom; if (this.startFrom < 0f) { startFrom = this.randomSpawnRate(); } this.spawnedObjects = new List <Transform>(); spawner = this.gameObject.DoSomethingLater(this.Spawn, startFrom); }
private void Spawn() { if (this.spawnPrefab.Length == 0) { Debug.LogError("No spawnPrefab have been set, please check the inspector."); return; } this.spawnedObjects.RemoveAll(item => item == null); if (this.spawnedObjects.Count < this.maxCount) { int index = 0; Transform tempPrefab = this.spawnPrefab[0]; if (this.spawnPrefab.Length > 1) { List <Transform> tempPrefabs = this.spawnPrefab.OfType <Transform>().ToList(); if (this.lastPrefab != null) { tempPrefabs.Remove(this.lastPrefab); } index = Random.Range(0, tempPrefabs.Count); tempPrefab = tempPrefabs[index]; this.lastPrefab = tempPrefab; } var spawnedTransform = Instantiate(tempPrefab) as Transform; if (!this.usePrefabTransform) { spawnedTransform.position = this.transform.position; } else { Vector3 difference = new Vector3( 0, this.transform.position.y - spawnedTransform.position.y, 0); spawnedTransform.position += difference; } //this.spawnPrefab[index].renderer.bounds.Intersects this.spawnedObjects.Add(spawnedTransform); } spawner = this.gameObject.DoSomethingLater(this.Spawn, this.randomSpawnRate()); }
void UpdateReady() { readyStatusLabel.title = iReady.ToString(); if (iReady == 0) { readyStatusLabel.title = "Go!"; ReadyController.Ready = true; } if (iReady > 0) { iReady--; this.timer = this.gameObject.DoSomethingLater(this.UpdateReady, 1f); } }