- Home /
Disable a script on collision
Hi, I'm trying to disable the ThirdPersonController script on my player on Collision so that he attaches himself onto a sphere and then the NormalWalking Script takes over so he floats around it like a moon's gravity. I'd like to be able to disable the ThirdPersonController on collision with the moon and enable the script when he collides with something else but I think I've done something wrong. Can anybody help me out?
function OnCollisionEnter (other : Collision) {
if (other.name == "world") { GameObject.ThirdPersonController.enabled=false; print("off"); }
if (other.name != "world") { GameObject.ThirdPersonController.enabled=true;
print("on"); }
}
Answer by Anxo · Nov 25, 2011 at 11:03 PM
Well, first you should always say what you are trying to do(as you are) but also mention what happens instead of the intended result. Like what error do you get and so on.
In this case I am going to guess you are getting an error because you are using GameObject instead of gameObject.
Answer by cystemic · Nov 25, 2011 at 11:10 PM
Sorry for being vague but I'm not getting any errors at all. The script just won't disable and my character falls to his death when the two collide and I walk off the edge.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
(C#)How To Disable Gravity From Script? 4 Answers
hide child object script - help 1 Answer
Disable script 1 Answer