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.

3 Answers

3

Try This:

Public Gameobject Player; // drag the car to it

void enable_script()
{
   Player.GetComponent<Script_Name> ().enabled = true;
}

I got it to work. Thanx. I appreciate your help.

–

When it can go call:

GameObject.FindGameObjectWithTag("Player").GetComponent<CarUserControl>().enabled = true;

Is the ending missing something? The code seems incimplete. Control is misspelled and the end brackets look wrong