Created
March 7, 2018 21:13
-
-
Save giljr/705a116ed07c1745355bf8c8eb1bfd03 to your computer and use it in GitHub Desktop.
Episode #10 Unity Game https://medium.com/@J.3/unity-game-debut-part-0-of-10-bc37729ef7fe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class EnemyController : MonoBehaviour { | |
public Soldier[] Enemies; | |
// Use this for initialization | |
void Start() | |
{ | |
//foreach (Soldier enemy in Enemies) | |
//{ | |
// enemy.Activate(); | |
//}//change this to Update() | |
} | |
// Update is called once per frame | |
void Update () { | |
if (GameController.Instance.IsGameOver) | |
return; | |
//Check if a soldier is currentely active | |
foreach (Soldier enemy in Enemies) | |
{ | |
if (enemy.IsActive) | |
{ | |
return; | |
} | |
} | |
//But I wanted the soldier appered randomly | |
// get index of each soldier in the list | |
//TODO: checked if it active first | |
int idxSoldier = Random.Range(0, Enemies.Length); | |
Enemies[idxSoldier].Activate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment