We will create a component that is able to see enemies nearby:
- Create the Visor component, declaring its member variables. It is important to add the following corresponding tags to Unity's configuration:
using UnityEngine; using System.Collections; public class Visor : MonoBehaviour { public string tagWall = "Wall"; public string tagTarget = "Enemy"; public GameObject agent; }
- Implement the function for initializing the game object in case the component is already assigned to it:
void Start() { if (agent == null) agent = gameObject; }
- Declare the function for checking collisions in every frame:
public void OnTriggerStay(Collider coll) { // next steps here }
- Discard the collision if it is not a target:
string tag ...