So i have the following code:
using UnityEngine;
using System.Collections;
public class WinOrLose : MonoBehaviour {
public static int heroCount;
public static int enemyCount;
private bool isHero;
private bool isEnemy;
private LevelManager levelManager;
// Use this for initialization
void Awake()
{
heroCount = 0;
enemyCount = 0;
}
void Start() {
isHero = (tag == "hero");
isEnemy = (tag == "enemy");
if (isHero)
{
heroCount++;
}
print("hero count is:" + heroCount);
if (isEnemy)
{
enemyCount++;
}
print("enemy count is:" +enemyCount);
levelManager = GameObject.FindObjectOfType<LevelManager>();
}
// Update is called once per frame
void Update () {
if (enemyCount <= 0)
{
SimulateWin();
}
//hypthetical function SimulateLose() does not exist
// else if (heroCount <= 0)
//{
// SimulateLose();
//}
}
void SimulateWin()
{
levelManager.LoadNextLevel();
}
}
for unity and i created 2 empty game objects, tagged one as hero and one as enemy.
I applied the script to both which might be cause of the following problem:
When i print the heroCount and enemyCount it prints 2 heroCounts to the console, each saying 1 and 1 enemyCount saying 0 and 1 saying 1. I am not sure why is prints 2 heroCounts and 2 enemyCounts could someone tell me what is wrong here? (also why is one enemyCount 0 and one of them 1)?
Thanks in advance