Making a Button in unity?

im creating a very simple scene in unity where u pick up a cube and place it on a button to make a bridge appear. i know almost nothing about scripting and am still very new to all of this so any information is helpful. i need the bridge to only activate when the cube has been placed on top of the button. and when the cube has been removed, the bridge needs to disappear. i can make the button activate when anything touches it with the activate trigger script but i want it to only activate on and off when the cube is touching it… any help would be great

You will want to specify the object by either using a tag comparison or name comparison. Below is an example using tag(since if you clone the cube its name will go from “Cube” to “Cube(Clone)” thus preventing the code from continuing…

function OnTriggerEnter(other:Collider)
{
    if(other.tag=="BridgeCube")
    {
        myBridge.collider.enabled=true;//turn on collider
        myBridge.renderer.enabled=true;//turn on renderer
    }
}
function OnTriggerExit(other:Collider)
{
    if(other.tag=="BridgeCube")
    {
        myBridge.collider.enabled=false;//turn off collider
        myBridge.renderer.enabled=false;//turn off renderer
    }
}

Not 100% sure if it works… but I’m thinking it will. Adjust the timer to 0.1 if you want instant release, if not… Poof. You’ve got a timer.

var Bridge : GameObject
var Timer : float = 1;

function Update(){

var TimerUser
//Timer Counts Down
TimerUser -= Time.Deltatime;


//Stops from going below 0
if(TimerUser < 0 )
TimerUser = 0;


//If there is time left, Bridge is active, else it is not active
if(TimerUser > 0)
Bridge.active = true;

else
Bridge.active = false;


}


function OnTriggerStay( Col: collider) {


if Col.GetTag("Box")
TimerUser = Timer;

}