I 'm doing a 2d platform game , I need to make enemies but do not know how. the enemy shall patrol and chase the player only when the player enters in the trigger of the enemy. i’d need a script because i am noob in c#. Sorry if I have not written correctly but i’m Italian. Thank you in advance. Please, is pretty urgent!
Well @thorr57,
what about my video in Italian about this? Sure, is 3D, but the system is identical, you only have to correct the target to ensure the correct plane is used
Cheers
-Pino
I would create attach a collider onto the enemy, in the shape of the region, and set it as a trigger. Then use some code like this in a script:
private bool seenPlayer = false;
void OnTiggerEnter() {
if (/* is it the player? */) seenPlayer = true;
}
void Update() {
if (seenPlayer) {
// do something
}
}
Then you would put whatever behavior you would like in place of the " // do something
". Just make sure that the player has a collider on it.