|
Helor I'm trying to seek help with this question as previously i tried on various codes on destroying game objects once i collide with them, it works but not for my AI character with character controller and few childs on it. I wanted to test if the collision works for 1 hit kill before i add in GUI health textures for it. But it seems like this script that i'm going to attach works on a small cube with box collider and with "is trigger" being ticked, but not towards my enemy. Hope someone can tell me another different way of coding it? or do i just need to tweak something else out of it? I'm still new to Unity between and am eager to learn more from other people as well :) Thanks heaps! Here's my code:
(comments are locked)
|
|
Hard to tell since it could be many things. Here's a list of what I think might be worth checking:
Also, I think @BeB_Wir3 is quite right, once you get it to work, it will try to destroy your player, not the enemy. That last line should be
(comments are locked)
|

Could you specify what "is not working" means? Does it print the message? Are there leftover GameObjects? Is anything happening at all?
sorry forgot to mention that. My enemy is not destroyed. yet it is still running around the area. Print message was not shown either.
what the enemy does is just continue attacking me.
i think you are trying to destroy the player. and you cant just destroy the player for data loss reasons. are there any errors?
Do you even have a trigger attached to the enemy? OnTriggerEnter can't be called without a trigger. It's obvious, but sometimes people forget :)