Advertisement
kadyr

Untitled

Oct 10th, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawner : MonoBehaviour
  6. {
  7. public GameObject spawnedObject;
  8.  
  9. private float timer = 0;
  10.  
  11. public float coolDown;
  12.  
  13. private int count = 0;
  14.  
  15. void Start()
  16. {
  17. var t = Instantiate(spawnedObject);
  18. t.transform.position = transform.position + new Vector3(Random.Range(-5, 5), 0,
  19. Random.Range(-5, 5));
  20. }
  21.  
  22. void Update()
  23. {
  24. timer += Time.deltaTime;
  25. Debug.Log(timer);
  26. if (timer > coolDown && count < 5)
  27. {
  28. var t = Instantiate(spawnedObject);
  29. t.transform.position = transform.position + new Vector3(Random.Range(-5, 5), 0,
  30. Random.Range(-5, 5));
  31. timer = 0;
  32. count += 1;
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement