- Home /
OnControllerColliderHit is not activating script.
I built a script that, when it (it being the particle system the script is attached to) collides with anything, the color animator is turned off.
function OnCollisionEnter (other : Collision)
{
GetComponent(ParticleAnimator).doesAnimateColor = false;
}
However, when I tried to get it to work with the CharacterController prefab, by using this script:
function OnControllerColliderHit (hit : ControllerColliderHit)
{
hit.collider.GetComponent(ParticleAnimator).doesAnimateColor = false;
}
Though my CharacterController did stop after hitting the collider on the particle system, it did not turn it off. Am I doing something wrong with the script, or is it another problem, perhaps with the settings (I did not change any).
Answer by PrimeDerektive · Jan 05, 2011 at 03:10 AM
The function OnControllerColliderHit can only be used in a script attached to an object with a CharacterController component... In your case, it seems you are trying to use it in a script attached to another object, thinking it will fire when your character hits it, but thats not how it works.
You would probably be better served making your particle system collider a trigger, and using OnTriggerEnter().
Derek Traver is right 100% if you are using OnControllerColliderHit this is only going to look for scripts only attached to your player. Your best option would be use OnTriggerEnter() :)