using UnityEngine; using System.Collections; public class vc : MonoBehaviour { public GameObject player; public zs[] _enemy; // enemy script // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnTriggerEnter(Collider col) { foreach(var e in _enemy) { if (col.gameObject.CompareTag("area") && e.enemy.activeSelf == false) { e.delete_enemy(); Debug.Log("delete"); } if (col.gameObject.CompareTag("area") && e.enemy.activeSelf == true) { e.Enemey_respwand(); Debug.Log("full"); } } } }
I’m trying to make something new in my code
It give me this error:
NullReferenceException: Object reference not set to an instance of an object
vc.OnTriggerEnter (UnityEngine.Collider col) (at Assets/vc.cs:23)
Second is this:
Can instead use foreach and remove “public zs[] _enemy;” use:
if(col.gameObject.CompareTag(“area”) && GameObject.FindGameObjectsWithTag(“enem”) == false)
{
e.delete_enemy();
Debug.Log(“delete”);
}