- Home /
panel go away UI
So I'm trying to create a simple panel at the start of the game. I have added a button which simply reads "Start!". i just want to hide the panel when the button is pushed. I have not a correct understanding for all of these functions about "onClick, pushDown" etc. What i have is Canvas>Panel>StartButton>text. I don't know how to continue my script or to which object I have to attach it to.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystem;
public void(){
if(Canvas.StartButton.onClick())
}
}
It sounds like you really need a basic tutorial for coding and Unity.
You can check out official Unity tutorials here. They are free
Answer by AaronXRDev · Nov 05, 2018 at 03:40 PM
The property you are looking for is "active". You can show and hide pretty much anything in Unity with it.
On the button itself in the On Click area you could do this:
That should make it so that when you click the button the Canvas hides. You can do this with any GameObject in the scene. If you want to do it programmatically you could do something like this:
public GameObject objectToHide;
private void OnMouseDown()
{
objectToHide.SetActive(false);
}
OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider. It will also fire if you tap on the object on mobile.