Another sense we're going to implement is Touch.cs
, which is triggered when the player entity is within a certain area near the AI entity. Our AI character has a box collider component and its IsTrigger
flag is on.
We need to implement the OnTriggerEnter
event that will be fired whenever the collider component is collided with another collider component. Since our tank entity also has a collider and rigid body components, collision events will be raised as soon as the colliders of the AI character and player tank are collided.
The code in the Touch.cs
file can be shown as follows:
using UnityEngine; using System.Collections; public class Touch : Sense { void OnTriggerEnter(Collider other) { Aspect aspect = other.GetComponent<Aspect>(); if (aspect != null) { //Check the aspect if (aspect.aspectName == aspectName) { print("Enemy Touch Detected"); } } } }
We implement the OnTriggerEnter
event to be fired whenever the collider...