- Home /
Destroy character when collision with enemy
hello i want to make my character to be destroyed when collisions with an enemy object(something like squid that moves(imported fbx model(no collisions or something)). What i must do?What collision i must add to the enemy and which script i must put on him? Aaah i almost forgot...Character has a camera(with camera script to follow the player)if it matters. Character picture: http://imageshack.us/photo/my-images/689/characterw.png/
enemy picture: http://imageshack.us/photo/my-images/528/enemy.png/
Thank you guys if you respond you are awsome
both of the above scripts will destroy the enemies, but what will be the script to destroy player character when it collides with the enemies game object ??please suggest me your precious answers
Answer by aldonaletto · Nov 15, 2011 at 07:20 PM
You can drag your model to the scene and add a box or sphere collider to it (menu Component/Physics/...). Adjust its dimensions, set Is Trigger in the Inspector and attach an OnTriggerEnter code to it:
function OnTriggerEnter(other: Collider){ if (other.tag == "Player"){ // check if it's the player, if you want Destroy(other.gameObject); } }
Answer by Wentzel · Nov 15, 2011 at 07:15 PM
Collision Tutorial & Destroying Tutorial
Attach to your Character.
function OnCollisionEnter(Col : Collision){
if(Col.gameObject.name == "enemy"){
Destroy(gameObject.find("enemy"));
}
}
Answer by Asmata · Jul 01, 2020 at 06:03 AM
Enemy attack the player and death my player send me script sir
Your answer
Follow this Question
Related Questions
How can I destroy my Player if only his Head or Body touch the ground. 3 Answers
Player not getting destroyed when touched by enemies 4 Answers
collision with wall so player dies 1 Answer
collision wont work 1 Answer
Flying collision 0 Answers