Zombies machen jetzt Geräusche wenn sie durch Disable sterben

This commit is contained in:
2024-04-07 01:22:42 +02:00
parent 3bdf7231e3
commit 993b38c057
18 changed files with 14581 additions and 15 deletions

View File

@ -5,6 +5,10 @@ using Utility;
public class ZombieSpawner : MonoBehaviour
{
[SerializeField]
List<Transform> SpawnPoints;
[SerializeField]
List<AudioClip> ZombieDeathByDisableSoundeffects;
[SerializeField]
GameObject ZombiePrefab;
[SerializeField]
@ -28,7 +32,7 @@ public class ZombieSpawner : MonoBehaviour
if (_spawnTimer <= 0)
{
Instantiate(ZombiePrefab, transform.position, Quaternion.identity, transform);
SpawnZombie();
_spawnTimer = _secondsPerAliveTime / _spawnRate;
}
}
@ -47,14 +51,27 @@ public class ZombieSpawner : MonoBehaviour
if (GameManager.Instance.ContextBuffer != null)
GameManager.Instance.RemoveContext("The Developer informs Gottfried that Zombies appeared outside so Gottfried better not leave the office");
// Destroy all children (zombies)
for (int i = 0; i < transform.childCount; i++)
{
KillZombiesByDisable();
}
KillZombiesByDisable();
}
private void SpawnZombie()
{
Transform pos = SpawnPoints[Random.Range(0, SpawnPoints.Count)];
Instantiate(ZombiePrefab, pos.position, Quaternion.identity, transform);
}
private void KillZombiesByDisable()
{
Destroy(transform.GetChild(i).gameObject);
for (int i = 0; i < transform.childCount; i++)
{
GameObject zombie = transform.GetChild(i).gameObject;
Vector3 zombiePosition = zombie.transform.position;
Destroy(zombie);
GameObject particleEffect = Instantiate(GameManager.Instance.ZombieDeathByDisableParticleEffect, zombiePosition, Quaternion.Euler(-90, 0, 0), GameManager.Instance.transform);
AudioSource audio = particleEffect.GetComponent<AudioSource>();
audio.clip = ZombieDeathByDisableSoundeffects[Random.Range(0, ZombieDeathByDisableSoundeffects.Count)];
audio.Play();
}
}
}