Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemySpawner : MonoBehaviour
- {
- BasicEnemyMovement basicEnemyMovementScript;
- [SerializeField]
- private List<GameObject> EnemyList = new List<GameObject>();
- [SerializeField]
- private GameObject Enemy1;
- [SerializeField]
- private GameObject Enemy2;
- [SerializeField]
- private GameObject Enemy3;
- public int EnemyIndex = 0;
- public float timer = 2;
- void Start()
- {
- EnemyList.Add(Instantiate(Enemy1));
- EnemyList.Add(Instantiate(Enemy2));
- EnemyList.Add(Instantiate(Enemy3));
- print(String.Format("There are {} enemies", EnemyList.Count));
- }
- void Update()
- {
- timer -= Time.deltaTime;
- if (timer < 0)
- {
- Debug.Log("Enemy timer");
- ChooseNextEnemy();
- timer = 2;
- }
- }
- void ChooseNextEnemy()
- {
- if (EnemyIndex >= EnemyList.Count)
- {
- EnemyIndex = 0;
- }
- basicEnemyMovementScript = EnemyList[EnemyIndex++].GetComponent<BasicEnemyMovement>();
- basicEnemyMovementScript.StartEnemyMovement();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement