- Home /
Turn off another script with Javascript
I have been looking through the forums for a few hours now, and haven't been able to find an answer.
In the game I am making, I already have it set up where if I press 1, it switches to a helicopter, and if I press 2, it switches to a car.
I would like to make it so that when I am in the helicopter, the car controls are switched off and the other way round when in the car.
So far I have found things like:
gameObject.GetComponent(Script).enabled = false
and it is all rather confusing. I am relatively new to this. It would be nice if somebody could point me in the right direction.
Thank you in advance.
Answer by Xtro · Aug 06, 2013 at 02:38 PM
gameObject.GetComponent(Script).enabled = false
this only helps you out if you have separate controller scripts for car and heli on the same game object. If you have this setup, you can just replace the "Script" in this line with your car or heli controller script name.
Ex:
gameObject.GetComponent(CarScript).enabled = false; gameObject.GetComponent(HeliScript).enabled = true;
Your answer

Follow this Question
Related Questions
Having trouble turning off gravity through script 1 Answer
Turn on/off Script 3 Answers
Light script flashes on and off 1 Answer
Jetpack flame only in the air 1 Answer
Whip controllers as in Castlevania 4 0 Answers