Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpawnerPosition : MonoBehaviour
- {
- bool spawningBool;
- [SerializeField] MovingCannon cannon;
- [SerializeField] GameObject ballPrefab1;
- [SerializeField] GameObject ballPrefab2;
- [SerializeField] GameObject ballPrefab3;
- GameObject[] ballsSpawn = new GameObject[2];
- [Range(2,3)] int spawnTime;
- Vector2 shooterPosition;
- Vector2 initialPosition;
- // Start is called before the first frame update
- void Start()
- {
- spawningBool = true;
- shooterPosition = cannon.transform.position - transform.position;
- initialPosition = transform.position;
- StartCoroutine(BallSpawner());
- }
- private void NewSpawnPosition()
- {
- transform.position = initialPosition;
- }
- private void TypeOfBallsSpawning()
- {
- for (int i = 0; i < ballsSpawn.Length; i++)
- {
- ballsSpawn[0] = Instantiate(ballsSpawn[0]) as GameObject;
- ballsSpawn[1] = Instantiate(ballsSpawn[1]) as GameObject;
- ballsSpawn[2] = Instantiate(ballsSpawn[2]) as GameObject;
- }
- }
- IEnumerator BallSpawner()
- {
- while (spawningBool)
- {
- yield return new WaitForSeconds(spawnTime);
- Instantiate(ballsSpawn, transform.position, transform.rotation);
- yield return new WaitForSeconds(3);
- }
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement