Custom buttons

I am working on a Light Scene.

  • I want to have 2 Buttons
    - Light On
    - Light Off
    In the play mode Light On only should display. when i press Light On , Light Off should replace Light On (while replacing, The button should replace in the exact place where Light On is)

Any suggestions would be appreciated…
Thanks in advance…

Put a canvas on the Scene, put a button on the canvas. Attach this cs script to it

private bool LS = false;
private Text myText;

void Start()
     myText = this.GetComponent<Text>();
     myText.text = "Light On";

public void LightSwitch()
     LS = !LS;
          myText.text="Light Off";
     } else {
          myText.text="Light On";

You;ll need to add using UnityEngine.UI; to the top of the script as well.

Put that script on the button and then look at the inspector. In the on OnClick area click + drag the button onto the empty slot that appears, then from the drop down select the script name → LightSwitch.

When clicked the function LightSwitch gets called and alters the state of the bool if it gets altered to true it changes the text to Light Off and if false to Light On.

Now this is a really simple thing so what you really need to do is watch some the excellent tutorials as it’ll save you a lot of time in the long run.