Commit fbbcb8fa authored by Cody A Burchett's avatar Cody A Burchett

toggling bug fix

parent ee05c260
......@@ -15,6 +15,8 @@ public class BaseEnemy : MonoBehaviour {
public Transform rightCollisionPos;
public Transform leftCollisionPos;
public bool hasEnteredView = false;
void Start()
{
body = GetComponent<Rigidbody2D>();
......
......@@ -19,12 +19,22 @@ public class ToggleEnemy : MonoBehaviour {
Plane[] camPlanes = GeometryUtility.CalculateFrustumPlanes(cam);
for (int i = 0; i < enemies.Count; i++)
{
BaseEnemy currentEnemy = enemies[i].gameObject.GetComponent<BaseEnemy>();
//check if enemy is in view of camera and disable if not
if (!GeometryUtility.TestPlanesAABB(camPlanes, enemies[i].bounds))
{
// enemies[i].gameObject.GetComponent<BaseEnemy>().enabled = false;
// enemies.Remove(enemies[i]);
if (currentEnemy.hasEnteredView)
{
currentEnemy.enabled = false;
enemies.Remove(enemies[i]);
}
}
else
{
if (!currentEnemy.hasEnteredView)
{
currentEnemy.hasEnteredView = true;
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment