Updated Fri Jan 18 2019 21:12
Every time I place a defender, it stops working and gets this error.
My code is below this, what should I do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooter : MonoBehaviour
{
[SerializeField] GameObject projectile, gun;
AttackerSpawner myLaneSpawner;
private void Start()
{
SetLaneSpawner();
}
private void Update()
{
if (IsAttackerInLane())
{
Debug.Log("shoot pew pew");
// TODO change animation state to shooting
}
else
{
Debug.Log("sit and wait");
// TODO change animation state to idle
}
}
private void SetLaneSpawner()
{
AttackerSpawner[] spawners = FindObjectsOfType<AttackerSpawner>();
foreach (AttackerSpawner spawner in spawners)
{
bool IsCloseEnough =
(Mathf.Abs(spawner.transform.position.y - transform.position.y)
<= Mathf.Epsilon);
if (IsCloseEnough)
{
myLaneSpawner = spawner;
}
}
}
private bool IsAttackerInLane()
{
if (myLaneSpawner.transform.childCount <= 0)
{
return false;
}
else
{
return true;
}
}
public void Fire()
{
Instantiate(projectile, gun.transform.position, transform.rotation);
}
}