pop-up GUI dialogue

Hi everyone!

Could someone tell me how to make a pop-up GUI dialogue?
We want to use a map in our project, which shows a head icon moving on the map, and when the icon moves to next point which represents the next level, it shows a GUI dialogue.

I have searched some posts but only know how to make a GUI that exists since the beginning of the game.

Here are our map.
First is the draft of pop-up dialogue, the second one shows the moving head icon.(I should upload the second one first :shock:)
Any help would be appreciated!! :smile:

350751--12191--$mapumity02_949.jpg
350751--12192--$mapumity_272.jpg

We use “SplineController_CS.zip” from forum to make path and control our icon movement.
We want to know how to define the loop is over and GUI can shows up.
Please help us! :frowning:

You can call code in the OnGUI function conditionally, so you can enable/disable the display of elements whenever you want:-

var showGUI: Boolean;

function OnGUI() {
   if (showGUI) {
      // Display made with GUI.Label, etc.
   }
}

Thank you andeeee!

And how do I define the cycle of movement is over, so we can set boolean to true?

Thanks again!

Is there still anyone? :frowning:

I’ve tried the following code:(You can ignore those be commented, I was trying something else.)

//private var showGUI: boolean;
private var showGUI2: boolean;
var player : GameObject;
//showGUI = false;
showGUI2 = false;

function Update () {
//	OnClick();
	var player = GameObject.FindWithTag("Player");
	ToPoint();
	OnGUI();
}

function ToPoint(){
	if ( player.transform.position.z <= 6)
		showGUI2 = true;
}

/*function OnClick() {
	//Press T to show text
	if(Input.GetKeyDown(KeyCode.T))
		showGUI = true;
    //Press N to hide text
	if(Input.GetKeyDown(KeyCode.N))
		showGUI = false;
}*/

function OnGUI(){
	/*if (showGUI){
		GUI.Box(Rect(100, 250, 100, 100),"SHOW GUI");
	}*/
	if (showGUI2){
		GUI.Box(Rect(400, 250, 100, 100),"It's SHOW GUI2");
	}
}

Set z<6 because we use “SplineController_CS” to make the path, and when z<6 the head icon would be behind the map.

But it still don’t work…Please help us!

We’re really stuck :cry:

Just a couple of things I wanted to point out.

  • Instead of setting your player object on every loop (Update() is looped continually), you should assign it in the Start() function (which is only called once on startup).

function Start() {
player = GameObject.FindWithTag(“Player”);
}

  • OnGUI() shouldn’t be called from your Update() function because Unity calls that function on its own.

  • In order to debug your code, try printing info to the console to see what’s happening under the hood.

function ToPoint(){
print("z: " + player.transform.position.z); //<- add
if ( player.transform.position.z <= 6)
showGUI2 = true;
}

I’m not familiar with “SplineController_CS.zip” at all, but looking at your code, things that could still be going wrong include:

  • More than one object tagged as “Player” (FindWithTag() returns the first object it find with that tag)
  • Player’s z is never <= 6 (perhaps rounding errors?)
  • “var player = GameObject.FindWithTag(“Player”);” might actually be creating a local variable and isn’t setting your class’s player variable. Removing the var in that line might fix that.

Sorry if this doesn’t help, I primarily work in C#. Good luck on your project!