Next Level Script (417198)

I found some script online that lets a button appear asking to go to the next level. When I get near a certain object. But it’s not working for some reason. When the game starts the button pops up even though I’m not near the object.

Here are the scripts

function OnGUI () {
	// Make a background box
GUI.Box (Rect (10,10,300,90), "Do You Want To Go To the Next Level?");

	// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
	if (GUI.Button (Rect (130,40,80,20), "Yeah")) {
	Application.LoadLevel(1);
	}
	}
var target : Transform;

function Update () {
var other = gameObject.GetComponent("GUI Style Script");

if ( Vector3.Distance(target.position, transform.position ) < 5) {
other.enabled = true;
}
if ( Vector3.Distance(target.position, transform.position ) > 5) {
other.enabled = false;
}
}

anyone???

I think your GuiComponent ist activated by default,
check this in the Inspector.

Greetings

how can i check it in the inspector?

Do you see that checkbox near that script named “SpielerLaufend”?

I guess your Component “GUI Style Script” is attached to your GameObject but still checked. Uncheck the box and it should work!

337635--11836--$test_137.jpg

u can’t check on inspector…
u r directly make this object via code…
if you wanna enable and disable it :
function OnGUI()/or if u r C# user void OnGUI
{
if(booleanShowButton)// writing boolean directly mean when it’s true mean ==true
{
// What you wanna make (like GUI.Button or Box that u made before)
}
}
OnUpdate()
{
//Distance condition { BooleanShowButton=true/false}
//I think you can use this code in GUI too… i didn’t try it. but i think you can… but you can’t use gui codes in here.
}

clayman it didn’t work. Deadman i’ll try it.

deadman i can’t seem to get it to work. can you post the code in javascript form?

here is one of the scripts i posted. modifyed by me.

//Once near whithin 25 distance of GameObject Finish
	// Make a background box
GUI.Box (Rect (10,10,300,90), "Do You Want To Countinue to next level");

	// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
	if (GUI.Button (Rect (130,40,80,20), "Yes I want to countinue")) {
	Application.LoadLevel(1);
	}

ç