How to Hide and Disable Buttons in Unity 4.6 (Solved)

Greetings. I need to complete a level, two buttons appear. One to end the game and another to restart the level. What is the procedure if possible in javascript? Thank You.

Hi,
I’m new to unity but i will try to help.
I see two ways of doing this :

  1. Use SetActive()
  2. Create the buttons at RunTime when the lvl is completed

The first one is easier :

1)Create and set up your 2 buttons and inactivate them (top left in the inspector)
2)Link the buttons to a script like this one :

It’s c# i don’t use Javascript, sorry.
But the key is to inactivate the buttons and activate them with SetActive.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UIManager : MonoBehaviour {

public Button Restart;
public Button End;
// Call this function when the lvl is completed
public void ShowButtons()
{
Restart.SetActive(true);
End.SetActive(true);
}

Hope this work for you.

1 Like

Thank you.

I will test and post the results.

The hint now works well. Just did some modifications because of the way that you passed me was not working. I’m putting the javascript code. I do not know C # well. Thank you for everything.

#pragma strict

import UnityEngine.UI;

var restart : Button;
var end : Button;

function Start () {

}

function Update ()
{
        restart.gameObject.SetActive(true);
        end.gameObject.SetActive(true);
}