I do not know why this while loop is infinite, I've had to restart my computer about 15 times, trying to solve this problem.
using UnityEngine;
using System.Collections;
using System;
public class CactusTrigger : MonoBehaviour
{
public Animator anim;
public EnemySpawner enemySpawner;
public bool justToCheck;
public GameObject AttackersHolder;
// Use this for initialization
void Start()
{
enemySpawner = FindObjectOfType<EnemySpawner>();
AttackersHolder = GameObject.Find("Attackers");
anim = GetComponent<Animator>();
SetMyLaneSpawner();
justToCheck = false;
}
void JustTo()
{
foreach (Transform child in AttackersHolder.transform)
{
//An infinite loop is going we need to fix it
while (child != null)
{
if (justToCheck != true)
{
justToCheck = true;
}
}
justToCheck = false;
}
if (justToCheck)
{
anim.SetBool("underAttack", true);
}
else if(justToCheck)
{
anim.SetBool("underAttack", false);
}
}
void Update()
{
JustTo();
}
void SetMyLaneSpawner()
{
EnemySpawner[] spawnerArray = GameObject.FindObjectsOfType<EnemySpawner>();
foreach (EnemySpawner spawn in spawnerArray)
{
if (spawn.transform.position.y == transform.position.y)
{
enemySpawner = spawn;
return;
}
}
Debug.LogError("Can't find spawner");
}
}