How to activate another Object with java script?

I have a GUIButton and a Object, name: “Car”. I will activate the car with the GUIButton. GUIButton have this script:

function OnGUI()
{
    GUI.enabled = true;
    if(GUI.Button(new Rect(0, 0, 200, 100),"Touch here to activate Car."))
    {
        gameObject.active = false;
    }
}

I know the “gameObject.active” it’s not good here, but how can activate my “Car” Object?

Have at the top of your script:

public var car : GameObject;

this will create a slot in the script inspector that you can drag the car onto. Then,

car.active = false;

will deactivate the car!

By “activate” do you mean enable/disable the entire object, or do you want to access a function on the object “Car”?

If you want to access a function, you would reference the car via a GameObject variable in the script with the GUI function, then use GetComponent to access the script and function you want.

private var carVariable : GameObject;

function Start () 
{
    carVariable = GameObject.Find("Car")
}

function OnGUI()
{
    GUI.enabled = true;

    if(GUI.Button(new Rect(0, 0, 200, 100),"Touch here to activate Car."))
    {
        carVariable.GetComponent(NameOfScriptOnCar).NameOfFunction(param1, param2, etc);
    }
}

An example. Drag your Car object to the car placeholder in the inspector.

   var Car : GameObject;
    
    // this should probably be in your car script or somewhere else, 
    // I don't know what you actually are trying to do here.
    function Awake () {
       Car.active = false;
    }
    
    function OnGUI()
    {
    
       GUI.enabled = true;
    
       if(GUI.Button(new Rect(0, 0, 200, 100),"Touch here to activate Car."))
       {
           gameObject.active = true;
       }
    
    }

Thanks for all answer. Unfortunately it’s not work for me. Maybe I wrote someting bad in the question. Sorry! So more simply: I want activate a Object with GUI button:

  1. Firt the Object is deactive(disable or was…)
  2. Player collusion a Trigger, Trigger activate a GUI button.
  3. If I click GUI button, the Object is active. GUI button activate the Object.

Please help.