- Home /
OnControllerColliderHit
I want the current game object to be destroyed on any collision,
function OnControllerColliderHit(collision: ControllerColliderHit){
if(collision)
{
Destroy(gameObject);
}
}
Destroy the object hitting the character or the character being hit?
Answer by Will748 · Jul 10, 2012 at 03:52 PM
For future reference for others, the script wasn't working as it was called 'collision', after renaming the script and deleting the script from the project window in Unity it was fine (for some reason the script remained in the project window even after renaming it so make sure it's deleted from the project window.) Also, Destroy(gameObject) works.
Answer by Will748 · Jul 09, 2012 at 11:23 PM
destroying the object hitting the character, I have attached this script to the bulletPrefab, ive also deleted the if statement as I think I dont need it ?
Answer by Will748 · Jul 10, 2012 at 12:56 AM
No it doesn't have a rigid body, does however have colliders
Answer by Will748 · Jul 10, 2012 at 01:57 PM
OK so if I want to apply the script to the object I should use OnCollisionsEnter ?, I have tried the following but doesn't seem to work
function OnCollisionEnter(collision:Collision){
Destroy(collison.gameObject);
}
Answer by Will748 · Jul 10, 2012 at 03:53 PM
I am also getting this funny error:
classID >= ms_MaxClassID || classID < 0
Your answer
![](https://koobas.hobune.stream/wayback/20220613073936im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Damage Player when this object collides the CharacterController? 2 Answers
OnControllerColliderHit is not activating script. 1 Answer
How to check direction of wall on character controller hit? 2 Answers
OnControllerColliderHit counting twice towards score 0 Answers
How do I use OnControllerColliderHit properly in c# 0 Answers