SHARE
TWEET

ball spawner

a guest Aug 14th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class SpawnerPosition : MonoBehaviour
  2. {
  3.     bool spawningBool;
  4.     [SerializeField] MovingCannon cannon;
  5.     [SerializeField] GameObject ballPrefab1;
  6.     [SerializeField] GameObject ballPrefab2;
  7.     [SerializeField] GameObject ballPrefab3;
  8.     GameObject[] ballsSpawn = new GameObject[2];
  9.     [Range(2,3)] int spawnTime;
  10.    
  11.  
  12.     Vector2 shooterPosition;
  13.     Vector2 initialPosition;
  14.  
  15.     // Start is called before the first frame update
  16.     void Start()
  17.     {
  18.         spawningBool = true;
  19.         shooterPosition = cannon.transform.position - transform.position;
  20.         initialPosition = transform.position;
  21.  
  22.         StartCoroutine(BallSpawner());
  23.     }
  24.  
  25.     private void NewSpawnPosition()
  26.     {
  27.         transform.position = initialPosition;
  28.     }
  29.  
  30.     private void TypeOfBallsSpawning()
  31.     {
  32.         for (int i = 0; i < ballsSpawn.Length; i++)
  33.         {
  34.             ballsSpawn[0] = Instantiate(ballsSpawn[0]) as GameObject;
  35.             ballsSpawn[1] = Instantiate(ballsSpawn[1]) as GameObject;
  36.             ballsSpawn[2] = Instantiate(ballsSpawn[2]) as GameObject;
  37.         }
  38.     }
  39.  
  40.     IEnumerator BallSpawner()
  41.     {
  42.         while (spawningBool)
  43.         {
  44.             yield return new WaitForSeconds(spawnTime);
  45.             Instantiate(ballsSpawn, transform.position, transform.rotation);
  46.             yield return new WaitForSeconds(3);
  47.         }
  48.     }
  49.  
  50.     // Update is called once per frame
  51.     void Update()
  52.     {
  53.        
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top