Hi
I'm trying to add a trigger to NPCs to detect once a player aproaches them.
So far, I got the following:
private class NPCBehaviour : MonoBehaviour
{
void Start()
{
NPCPlayerApex npc = this.gameObject.GetComponent<NPCPlayerApex>();
// Set our position and rotation according to our "parent"
this.transform.position = npc.transform.position;
this.transform.rotation = npc.transform.rotation;
// Add a rigidbody if there is none (NPCPlayerApex should always have one already)
this.rigidbody = this.gameObject.GetComponent<Rigidbody>();
if (this.rigidbody == null) this.rigidbody = this.gameObject.AddComponent<Rigidbody>();
this.rigidbody.useGravity = false;
this.rigidbody.isKinematic = true;
this.rigidbody.detectCollisions = true;
this.rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
// Add a shpere collider
this.sphere_collider = this.gameObject.AddComponent<SphereCollider>();
this.sphere_collider.isTrigger = true;
this.sphere_collider.center = this.transform.position;
this.sphere_collider.radius = 5f;
}
void OnTriggerEnter(Collider collider)
{
MonoBehaviour.print("OnTriggerEnter triggered");
}
}But OnTriggerEnter is never called :'(
I also tried setting this.gameObject.layer = (int)Layer.Reserved1; but that does not help either.
Any one have an idea?