FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

descriptionProblem with the gui message

more_horiz
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 ?

descriptionRe: Problem with the gui message

more_horiz
@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

_________________
-BryceCain25
Permissions in this forum:
You cannot reply to topics in this forum