I want activate a Object with GUI button: 1. Firt the Object is deactive 2. Player collusion a Trigger, Trigger activate a GUI button. 3. If I click GUI button, the Object is active. So GUI button activate the Object.
Please help with javascript for the GUI button.
//Inactive Objects script
//Inactive obj has isTrigger Collider attached
public var myMenu:MyMenu;
function OnTriggerEnter(other:Collider)
{
if(other.CompareTag("Player"))
{
myMenu=other.GetComponent(MyMenu);
myMenu.showActivateButton=true;
myMenu.objectToActivate=gameObject;
}
}
function OnTriggerExit(other:Collider)
{
if(other.CompareTag("Player"))
{
myMenu.showActivateButton=false;
}
}
//MyMenu.js
public var objectToActivate:GameObject;
public var showActivateButton:boolean;
function OnGUI()
{
if(showActivateButton)
{
if(GUI.Button(myRect,"Activate Object")
{
objectToActivate.active=true;
showActivateButton=false;
}
}
}
This relies on: MyMenu.js is a component on the player, the trigger is on the inactive object, player is tagged as “Player”,
I don’t know why I can’t use ,Vote Up" button…BUT THANKS! I’TS WORK AND HELPED ME A LOT! THANK YOU!