Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » Problem with the gui message

Problem with the gui message

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Problem with the gui message on Mon Aug 25, 2014 7:56 am

X-raptor


Member [Lv. 1]
Member [Lv. 1]
How do I add a message to the gui in the central part of the screen for five seconds, and then after five seconds, the message should disappear ?

View user profile

2 Re: Problem with the gui message on Sat Aug 30, 2014 9:56 pm

BryceCain25


SUPER MODERATOR
SUPER MODERATOR
X-raptor wrote:How do I add a message to the gui in the central part of the screen for five seconds, and then after five seconds, the message should disappear ?
Easy there sir!
By the way, welcome to Unity Ninja, ask if you need anymore help than this.
start by adding some simple gui mechanics.
here is a start-off script.
Please note, you will be able to change the string in the inspector at any time, meaning you can change the message that appears Smile

Code:
var guiMessage : String;
var howlong : int;
var mystyle : GUIStyle;
var leveltoload : String;
function Start () {

}

function Update () {

}
function OnGUI () {
if(GUI.Button(Rect (Screen.width/2 - 50, Screen.height/2 + 10, 100, 50), guiMessage, mystyle)) {
Load();
}
}
function Load () {
yield WaitForSeconds(howlong);
Application.LoadLevel(leveltoload);
}

this is an example of a button with a style, next is a label Smile

Code:
var guiMessage : String;
var howlong : int;
var mystyle : GUIStyle;
var leveltoload : String;
function Start () {
guiMessage = "";
}

function Update () {

}
function OnGUI () {
GUI.Label(Rect (Screen.width/2 - 50, Screen.height/2 + 10, 100, 50), guiMessage, mystyle);
guiMessage = "";

}
function GuiText () {
yield WaitForSeconds(howlong);
guiMessage = "";
}
I cannot for sure know if this will completely work.
now here is the Label code (probably what you were looking for), it's more sophisticated, the last one, I just wrote pretty quickly, this one will conform to the screen resolution, I don't necessarily know about the last one.
Code:
var guiMessage : String;
var howlong : int;
var mystyle : GUIStyle;
var leveltoload : String;
var w = 0.3; // proportional width (0..1)
  var h = 0.2; // proportional height (0..1)
  private var rect: Rect;
function OnGUI () {
 
  rect.x = (Screen.width*(1-w))/2;
  rect.y = (Screen.height*(1-h))/2;
  rect.width = Screen.width*w;
  rect.height = Screen.height*h;
  GUI.Label(rect, guiMessage);
  GoOut();
}
function GoOut () {
yield WaitForSeconds(howlong);
guiMessage = null;
}
hope this helped, you can use the mystyle variable if you want,
the rest is pretty much up to you
if you want to do this in-game and not in a menu, you will have to trigger it, using OnTriggerEnter or OnTriggerStay.
contact me if you need anymore help

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum