Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawning : MonoBehaviour
  6. {
  7. public GameObject obstacle;
  8. private bool spawning = true;
  9. IEnumerator SpawnItems(){
  10. while(true){
  11. if(spawning){
  12. var obs = ObjectPools.Instance.Get();
  13. obs.transform.position = obstacle.GetComponent<Transform>().GetChild(Random.Range(0, 4)).position;
  14. obs.transform.rotation = transform.rotation;
  15. obs.gameObject.SetActive(true);
  16. }
  17. else{
  18. Instantiate(obstacle);
  19. }
  20. spawning = !spawning;
  21. yield return new WaitForSeconds(10f/PlayerController.speed);
  22. }
  23. }
  24. // Start is called before the first frame update
  25. void Start()
  26. {
  27. StartCoroutine(SpawnItems());
  28. }
  29.  
  30. // Update is called once per frame
  31. void Update()
  32. {
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement