Advertisement
Guest User

Untitled

a guest
Jun 27th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class SpawnManager : MonoBehaviour {
  4.  
  5. public GameObject[] animalPrefabs;
  6. private Vector3 spawnPos = Vector3.zero;
  7.  
  8. private float rangeX = 15;
  9. private float rangeZTop = 15;
  10. private float rangeZBottom = 2;
  11. private float zWhenXSpawning = 19f;
  12. private float xWhenZSpawning = 22f;
  13.  
  14. private float startDelay = 2f;
  15. private float repeatDelay = 0.5f;
  16.  
  17. private void Start() {
  18. InvokeRepeating("SpawnRandomAnimal", startDelay, repeatDelay);
  19. }
  20.  
  21. private void SpawnRandomAnimal() {
  22. int animalIndex = Random.Range(0, animalPrefabs.Length);
  23.  
  24. int direction = Random.Range(1, 4);
  25. switch(direction) {
  26. case 1: //Top
  27. Instantiate(animalPrefabs[animalIndex],
  28. new Vector3(Random.Range(-rangeX, rangeX), 0f, zWhenXSpawning),
  29. Quaternion.Euler(0, 180, 0));
  30. break;
  31.  
  32. case 2: //Left
  33. Instantiate(animalPrefabs[animalIndex],
  34. new Vector3(-xWhenZSpawning, 0f, Random.Range(rangeZBottom, rangeZTop)),
  35. Quaternion.Euler(0, 90, 0));
  36. break;
  37.  
  38. case 3: //Right
  39. Instantiate(animalPrefabs[animalIndex],
  40. new Vector3(xWhenZSpawning, 0f, Random.Range(rangeZBottom, rangeZTop)),
  41. Quaternion.Euler(0, -90, 0));
  42. break;
  43. }
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement