- Home /
Showing a text confirmation message on HMD when a button is clicked and also making it disappear automatically
Hello,
I have some challenges like
1. Showing a text-based confirmation message/pop-up on HMD when a button is clicked (FYI, my scene is 3D based, not 2D)
2. Making the message disappear automatically 3-5 sec later.
In my current 3D scene on Unity, each button is linked with different events, and I would like to show one simple sentence such as "your mission is completed!" when any of those buttons are clicked and make it disappear automatically 3-5 sec later. So far, I have been able to use the 'On Click ()' script for the buttons and the events, but I can't figure out how to show the confirmation message and make it disappear. It doesn't matter whether it looks like a 'pure text message' or a pop-up, and I just want to show the confirmation message to a user for a few seconds.
Most of the similar tutorials I've found online is to show a pop-up on a 2D game. But, I do need to show the message directly to HMD because my scene is 3D and I'm working with VR devices. I was also looking for assets but couldn't find one that is helpful..
I would really appreciate it if you can share any resourceful information with me.
Thank you!
Are you using the UI Canvas?
What you can do is create a UI Text and place it in the middle of the canvas. Disable it by default. Create or modify your existing event scripts to reference the UI Text (You'll need to add "using UnityEngine.UI;" at the top. Add the following functions which will be called by your different events:
public Text UIPopupText;
//Call from some function
void SomeEvent()
{
//Player finishes level
DisplayPopup("Level Complete!", 5f);
}
//Displays the message and invokes the message to be closed in x duration
public void DisplayPopup(string message, float duration)
{
CancelInvoke("ClosePopup");
UIPopupText.SetActive(true);
UIPopupText.text = message;
Invoke("ClosePopup", duration);
}
//The Close function which will be invoked by the DisplayPopup function
private void ClosePopup()
{
UIPopupText.SetActive(false);
}
Answer by Carterryan1990 · Apr 19, 2018 at 02:48 AM
A simple text off script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
Public class TextOff : $$anonymous$$onobehavior {
public Text _text;
public float _textOffTimer;
void Start()
{
Invoke("TextOFF" _textOffTime);
}
void TextOFF() { _text.enabled = false;
}
}