Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MobSpawnerScript : MonoBehaviour
  6. {
  7. [SerializeField]
  8. public GameObject wolf;
  9. [SerializeField]
  10. public GameObject bunny;
  11.  
  12. [SerializeField]
  13. public int wolfAmount;
  14. [SerializeField]
  15. public int bunnyAmount;
  16.  
  17. [SerializeField]
  18. public float wolfLifespan;
  19. [SerializeField]
  20. public float wolfRandomSpeedMin;
  21. [SerializeField]
  22. public float wolfRandomSpeedMax;
  23.  
  24. public float xPosition;
  25. public float zPosition;
  26. //private float yPosition;
  27. private void Start()
  28. {
  29. SpawnAnimal("wolf");
  30. //WolfLifespan();
  31. }
  32.  
  33. void SpawnAnimal(string species)
  34. {
  35. if(species == "bunny")
  36. {
  37. SpawnBunny();
  38. } else if (species == "wolf"){
  39. SpawnWolf();
  40. }
  41. }
  42.  
  43.  
  44. void SpawnWolf()
  45. {
  46. while (wolfAmount > 0)
  47. {
  48. Debug.Log("Creating" + wolfAmount + "wolf");
  49.  
  50. xPosition = Random.Range(-10f, 10f);
  51. zPosition = Random.Range(-10f, 10f);
  52. //yPosition = Random.Range(5f, 7f);
  53.  
  54. Instantiate(wolf, new Vector3(xPosition, 0f, zPosition), Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f));
  55.  
  56. wolfAmount--;
  57. }
  58. }
  59. void SpawnBunny()
  60. {
  61. while (bunnyAmount > 0)
  62. {
  63. Debug.Log("Creating" + bunnyAmount + "bunny");
  64.  
  65. xPosition = Random.Range(-10f, 10f);
  66. zPosition = Random.Range(-10f, 10f);
  67. //yPosition = Random.Range(5f, 7f);
  68.  
  69. Instantiate(bunny, new Vector3(xPosition, 0f, zPosition), Quaternion.Euler(0.0f, Random.Range(0.0f, 360.0f), 0.0f));
  70.  
  71. bunnyAmount--;
  72. }
  73. }
  74.  
  75. public void NewWolf(Vector3 newPosition)
  76. {
  77. GameObject newWolf = Instantiate(wolf, transform.position, transform.rotation);
  78. newWolf.transform.position = newPosition;
  79. newWolf.transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
  80. }
  81. /*void WolfLifespan()
  82. {
  83. WolfController wolfController = GameObject.Find("Wolf").GetComponent<WolfController>();
  84.  
  85. wolfController.wolfLifespanDuration = wolfLifespan;
  86. wolfController.randomSpeedMin = wolfRandomSpeedMin;
  87. wolfController.randomSpeedMax = wolfRandomSpeedMax;
  88. }*/
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement