To disable, you can only delete?
using UnityEngine; using System.Collections; public class Visor : MonoBehaviour { public string tagWall = "Wall"; public string tagTarget = "Enemy"; public GameObject agent; // Use this for initialization void Start() { if (agent == null) agent = gameObject; print("indexer"); } public void OnTriggerStay(Collider coll) { string tag = coll.gameObject.tag; if (!tag.Equals(tagTarget)) return; GameObject target = coll.gameObject; Vector3 agentPos = agent.transform.position; Vector3 targetPos = target.transform.position; Vector3 direction = targetPos - agentPos; float length = direction.magnitude; direction.Normalize(); Ray ray = new Ray(agentPos, direction); RaycastHit[] hits; hits = Physics.RaycastAll(ray, length); int i; for (i = 0; i < hits.Length; i++) { GameObject hitObj; hitObj = hits[i].collider.gameObject; tag = hitObj.tag; if (tag.Equals(tagWall)) return; } // TODO // target is visible code your behaviour below /* //вариант поведения с Arrive/Leave: GetComponent<Face>().enabled = true; GetComponent<Arrive>().enabled = true; GetComponent<Leave>().enabled = true; GetComponent<Wander>().enabled = false; */ //вариант поведения с pursue: GetComponent<Face>().enabled = true; GetComponent<Pursue>().enabled = true; GetComponent<Wander>().enabled = false; } public void OnTriggerExit(Collider coll) { /* //вариант поведения с Arrive/Leave: GetComponent<Face>().enabled = false; GetComponent<Arrive>().enabled = false; GetComponent<Leave>().enabled = false; GetComponent<Wander>().enabled = true; */ //вариант поведения с pursue: //if (coll.name == "Player") //{ GetComponent<Face>().enabled = false; GetComponent<Pursue>().enabled = false; GetComponent<Wander>().enabled = true; //} } }