Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class BoxController : MonoBehaviour
  6. {
  7. public GameObject box;
  8. public int boxCount;
  9. void Start()
  10. {
  11.  
  12. }
  13.  
  14. void Update()
  15. {
  16. boxCount = GameObject.FindGameObjectsWithTag("box").Length;
  17. if (!IsInvoking("FallBox"))
  18. {
  19. if (boxCount < 5)
  20. {
  21. Invoke("FallBox", 5);
  22. }
  23. }
  24. }
  25. void FallBox()
  26. {
  27. boxCount += 1;
  28. Vector2 position = new Vector2(Random.Range(-14f, 15f), Random.Range(10f, 20f));
  29. Instantiate(box, position, Quaternion.identity);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement