Advertisement
SizilStank

Untitled

Nov 8th, 2022
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CentaActiveBehavior : MonoBehaviour  //This is on the GameObject in the Scene disabled...
  6. {
  7.  
  8.    
  9.  
  10.     [SerializeField] private GameObject _spawnInCenta;
  11.     [SerializeField] private GameObject _spawnInCenta01;
  12.     [SerializeField] private float _spawnWaitTine;
  13.     [SerializeField] private bool _canWeSpawn;
  14.  
  15.     private void Start()
  16.     {
  17.         _canWeSpawn = true;
  18.         StartCoroutine(SpawnInCenta());
  19.         StartCoroutine(SpawnInCenta01());
  20.     }
  21.  
  22.     //public void CallAwesomeCoroutine() { StartCoroutine("SpawnInCenta"); }
  23.     IEnumerator SpawnInCenta()
  24.     {
  25.         while (_canWeSpawn == true)
  26.         {
  27.             EventManager.OnCentaAddToList();//Adding to a list on the SpawnManager class
  28.             yield return new WaitForSeconds(2);
  29.             Vector3 _randomPosY = new Vector3(11, Random.Range(4.5f, 0f), 0);
  30.             GameObject spawnIn = Instantiate(_spawnInCenta, _randomPosY, Quaternion.identity);
  31.             yield return new WaitForSeconds(_spawnWaitTine);
  32.             Debug.Log("CENTA");
  33.         }
  34.     }
  35.  
  36.     IEnumerator SpawnInCenta01()
  37.     {
  38.         while (_canWeSpawn == true)
  39.         {
  40.             EventManager.OnCentaAddToList();//Adding to a list on the SpawnManager class
  41.             yield return new WaitForSeconds(5);
  42.             Vector3 _randomPosY = new Vector3(-11, Random.Range(4.5f, 0f), 0);
  43.             GameObject spawnIn01 = Instantiate(_spawnInCenta01, _randomPosY, Quaternion.identity);
  44.             yield return new WaitForSeconds(_spawnWaitTine);
  45.             Debug.Log("CENTA");
  46.         }
  47.     }
  48.  
  49.     public void CanWeSpawn()
  50.     {
  51.         _canWeSpawn = false;
  52.     }
  53.  
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement