November 2018
Beginner
246 pages
5h 23m
English
Another sense we're going to implement is Touch.cs, which is triggered when the player entity is within a specific range of the AI entity. Our AI character has a box collider component, and its Is Trigger flag is on.
The code in the Touch.cs file is as follows:
using UnityEngine;
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 need to implement the OnTriggerEnter event that is fired whenever the collider component collides with another collider component. Since our tank entity also has a collider and rigid body components, a collision event occurs ...
Read now
Unlock full access