- Home /
Please Help!!! Enable/Disable Script!!!
Hello everybody. I am new to Unity so I get confused and frustrated pretty quickly lol. Im building a racing car game and Im trying to enable or toggle the car's driving script after my count down timer says "3, 2, 1, GO!". I want a separate JavaScript from the timer script.
The car name and tag is "Player" The script in the car is "CarUserControl"
Note: All the cars (Player and AI cars) are children in a gameobject called "Cars" Dont know if that makes a difference when tracking the gameobjects/components.
Is there scripts or videos I can look at for this? Ive searched google, unity and youtube and nothing seems to work for me.
Will appreciate your help. Thanks in advance.
Answer by divvy81 · May 04, 2015 at 10:30 AM
Try This:
Public Gameobject Player; // drag the car to it
void enable_script()
{
Player.GetComponent<Script_Name> ().enabled = true;
}
Answer by hbalint1 · May 03, 2015 at 10:04 PM
When it can go call:
GameObject.FindGameObjectWithTag("Player").GetComponent<CarUserControl>().enabled = true;
Answer by SwagGamez · May 04, 2015 at 10:35 AM
Is the ending missing something? The code seems incimplete. Control is misspelled and the end brackets look wrong