ending game?

Hi, I’m new to scripting, and making games. I made my whole game, and the only thing I need done is a script to end the game when you touch an object.

I want it to fade out, and then just exit to the desktop :slight_smile:

can anyone make one for me, or tell me where there is an easy tutorial for it? ^^

That helped me a little, but I still don’t know how to make it exit to the desktop?

Application.Quit()

–Eric

1 Like

Thanks ^^ But how do I make it happen, when I touch the object, and not just when the game starts?

Please someone, i’ll need to know soon… I’ve tried to make a script, to just make the game end, but it doesn’t work… what am I doing wrong?


var quit = true;

function Touch()
{
if(quit)
{
Application.Quit();
}
}

Just make an on function activate, Application (Quit) and attach it to the endgame activator.

Just make an on function activate, Application (Quit) and attach it to the endgame activator. You will need to add a timer for the fade also.

okay, I didn’t really understand that… or it just didn’t work… could you please copy/paste mine, and then put in the changes?

Okay… can someone please just make a quick script, for closing the game, when touching a specific object? no need for fade or anything, just closing the game?

Can’t someone just please make one that makes it close when you press esc? Please, anything that makes the game close O.o

It sounds like you need to take a step back and learn the basics of Unity such as using triggers, input, and simple scripts.

I would suggest to go through one of our tutorials:
http://unity3d.com/support/resources/tutorials/

Once you have that basic understanding, doing the things you ask about are very simple with the pointers people have already given in this thread.

Rune

1 Like

Try this, this should make the game close when you press the defined key.

function Update () {
	// Did the user press the quit key?
	if (Input.GetButton ("INSERT QUIT KEY HERE"))
		Application.Quit();
	}

Make sure you set the quit key up in the Project settings/ Input menu. Caps do matter.

Edit: You do know that pressing Alt-F4 quits whatever application windows has open right? Use this untill you get a quit button setup.

Take what you need from this script, but basically it lets you click on say an “exit” button and quits the game or click on a “load” or “start game” button to load a scene. Also make sure after you apply this script to your exit button object make sure to check the isQuit box in the inspector.

var isQuitButton = false;

function OnMouseEnter()
{
// CHange color of text /
renderer.material.color = Color.red;
}

function OnMouseExit()
{
// CHange color of text /
renderer.material.color = Color.white;
}

function OnMouseUp()
{

// are we dealing witha quit button //
if( isQuitButton )
{
// quit the game //
Application.Quit();
}
else
{
// load level //
Application.LoadLevel(1);
}
}

I think this will only work in a Build Version so you’ll have to use Debug.Log() untill you build a version to test

function OnGUI () {
if(GUIEnabled) {
if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2 - 60,160,20), “Exit Game”)) {
Application.Quit();
}
}
}