- Home /
How to make auto hide UI ?
hi, sorry for grammar..
right now i'm working on mobile application (android). when game enter main scene, i want to make ui canvas to disappear when no user input / touch and appears when user touch screen again.
what i have try is: using invoke (5 sec delay) to hide UI > make a button (UI button) as big as screen size > then attach showUI function on OnClick. but the problem is, when i touch the screen to make UI appear, its keep counting 5 sec to hide UI again.
what i wanted is, i want to make ui stay visible when user still touch the screen. here my script:
using UnityEngine;
using System.Collections;
public class AutoHiddenUI : MonoBehaviour {
public GameObject uiSystem;
public GameObject watermark;
public GameObject hiddenButton;
void Start ()
{
Invoke ("HideUISystem", 5);
}
void HideUISystem ()
{
uiSystem.SetActive (false);
watermark.SetActive (true);
// hiddenButton.SetActive (true);
}
public void ShowUISystem ()
{
uiSystem.SetActive (true);
watermark.SetActive (false);
// hiddenButton.SetActive (false);
Invoke ("HideUISystem", 5);
}
}
thanks in advanced
Answer by BudyDubby · May 12, 2015 at 04:00 AM
okay, i'm found it by myself,
using UnityEngine;
using System.Collections;
public class AutoHiddenUI : MonoBehaviour {
public GameObject uiSystem;
public GameObject watermark;
void Update ()
{
if (Input.touchCount != 0) {
uiSystem.SetActive (true);
watermark.SetActive (false);
CancelInvoke ("HideUISystem");
} else {
Invoke("HideUISystem", 5);
}
}
void HideUISystem ()
{
uiSystem.SetActive (false);
watermark.SetActive (true);
}
}
Your answer
Follow this Question
Related Questions
SetActive true not working on UI object 2 Answers
one button to hide and unihed gameobjects 0 Answers
Detect if UI Image is in a trigger 1 Answer
Only Rotate UI HUD on orientation change. 0 Answers
How to shrink text size 1 Answer