set timer to hide button

hello, sorry, i’m still new to unity and this is my first time i’m joining this forum. :wink:

i make an application using unity, i have some problem to hide button after several seconds. if some one of you knows how to do this, please help me. thanks. :smile:

this is my script:

var Delete : Texture;
var Duplicate : Texture;

var deleteObject : boolean = false;
var duplicate : boolean = false;

function OnMouseUp ()
{
deleteObject = true;
duplicate = true;

}

function OnGUI()
{

if (deleteObject)
{
GUI.backgroundColor = Color.white;
if(GUI.Button(Rect(465,50,40,40), GUIContent(Delete)))
{
Destroy(gameObject);
}
}

if (duplicate)
{
GUI.backgroundColor = Color.white;
if(GUI.Button(Rect(510,50,40,40), GUIContent(Duplicate)))
{
Instantiate (gameObject);
}
}

}

http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Invoke.html
Also use the tags when you post code.

thanks appels, but this one is for game object, i want to hide the button (Delete button and Duplicate button) after few seconds.
do you have any other referances?
thanks a lot. :slight_smile:

You can use Invoke to schedule a call to a method that’ll hide your buttons (set the booleans to false).

how do i do that? sorry, i’m not good in scripting.

maybe something like this?

function OnGUI(){
Invoke("HideButton", 2);
}

function LaunchProjectile () {
    deleteObject = true;
}

Don’t put Invoke in OnGUI() unless you really mean for it to be called twice per frame. If you want something to destroy itself after 2 seconds then you would do

void Start()
{
     Invoke("deleteMe", 2);
}

void deleteMe()
{
     Destroy(gameObject);
}

thanks guys, it’s really helpfull, thanks.