This question was
closed Jun 12, 2017 at 01:09 PM by
Hellium for the following reason:
Duplicate Question
Question by
AarshSinghVishen · Jun 12, 2017 at 01:08 PM ·
scripting problemnullreferenceexception
Why do i get NullReferenceException here?
List<Collider> trig;
// Use this for initialization
void Start()
{
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Zombie")
{
if (!trig.Contains(other))
{
trig.Add(other);
}
for (int i = 0; i < trig.Count; i++)
{
Vector3 dir = trig[i].gameObject.transform.position.normalized*-1;
transform.Translate(dir * 0.5f * Time.deltaTime);
}
}
// Update is called once per frame
}
private void OnTriggerExit(Collider other)
{
if (trig.Contains(other)) {
trig.Remove(other);
}
}
Comment