need a script

i need a scpit that can start the game and quit game
i have tried lot of them but nothing worked

The scripts i’ll give you are in Javascript, so you need to paste them in Javascript script, notC#.

First thing you need to do is to set up your build : go to File/Build Settings and add the scene you want in your build (Your menu should be 0 and your first level should be 1.)If you don’t do that, scripts wont work.

Next, create a new GUITexture in your Menu Scene. Put there any texture you want, this will be the LoadGame button.

Create a Javascript file. Open it and paste this :

#pragma strict

var couleurBouton : Color;


function OnMouseDown(){
	
	//This will load the level (I've put 1 assuming your level is 1 in your build, but you can (must) change that accordingly to how your build is set up.
	Application.LoadLevel(1);

}

function OnMouseEnter(){

	//This will change the color of your button (here to a green color)
	couleurBouton = Color(0.5, 0.8, 0.5);
	guiTexture.color = couleurBouton ;
}

function OnMouseExit(){

	//This will reset the color of your button
	couleurBouton = Color(0.5, 0.5, 0.5);
	guiTexture.color = couleurBouton ;
	
}

Save the script.Then you have to put this script on your Load game button.

Next, create a new GUITexture and assign to it your Quit texture.
Create a new Javascript script. Open it and paste this code:

#pragma strict

var couleurBouton : Color;


function OnMouseDown(){
	
	//This will quit the game.
	Application.Quit();

}

function OnMouseEnter(){

	//This will change the color of your button (here to a green color)
	couleurBouton = Color(0.5, 0.8, 0.5);
	guiTexture.color = couleurBouton ;
}

function OnMouseExit(){

	//This will reset the color of your button
	couleurBouton = Color(0.5, 0.5, 0.5);
	guiTexture.color = couleurBouton ;
	
}

Save it. Add this new script to your Quit Button.

That’s it you now have a start button and a quit button. Here i gave you all the steps, if you can’t make it work, redo some tutorials showing the very basics of unity and coding.

ok
i already have the text i have made them but i only have the start and Quit
but u side loedgame ?
how do i do that ?

Start will just do fine, but what it really does is to load a level from your build. Again, if you don’t set up your build, this won’t work. But the quit button will work even if you don’t set up your build. But the quit button won’t work if you play your game in the editor, you must build your game and play the builded game to have the quit button. In editor, it’s ignored because you just have to hit the start stop button of the editor.

works beautifuly
thank u sooooo much
i was trying to fix this the last 4 days
all day up

the quit does not work coz i am in the game

sir if i am right the first script is for the start and the other script is for quit right ?

Indeed, first script is to start your game, the second one (wich will only work in builded game, not in Unity) is the quit button.

it showes me this

MissingComponentException: There is no ‘GUITexture’ attached to the “quit” game object, but a script is trying to access it.
You probably need to add a GUITexture to the game object “quit”. Or your script needs to check if the component is attached before using it.
UnityEngine.GUITexture.set_color (Color value) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/Graphics.cs:3231)
strt and quit.OnMouseExit () (at Assets/strt and quit.js:47)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents(Int32, Int32)

but it works great

The error is there because your buttons must be GUIText and not GUITextures. You have 2 solutions to get this work completly. First is just to remove the OnMouseEnter and OnMouseExit functions of the scripts : The button will still work but won’t change color. The second one, wich you should do is to open a program like photoshop, create 2 files, type Start in one, Quit in the secon and save those files as PNG. Then you go back inUnity, go to your Menu scene, and create 2 GUITextures. Import those 2 image you just made. Drag the Start texture in the inspector of one of the GUITextures, drag the other to the other. poisition them and add the start script to the start GUI texture and the quit script to the Quit GUITexture. And you’ll no longer have errors messages.

i am a photoshop artist


this is how every thing looks
that error was a old one so dont worry

but even if i make the game complet it well the error effect it ?

The game should work even with that error, because it’s a runtime error, not a compiling error. But’s it’s better to not have runtime errors.

so i have to fix it ?

Yeah, you should. Just remove the OnMouseEnter and OnMouseExit functions (and the couleurBouton variable) from the scripts.
This would be enough to make buttons work :

Start button :

#pragma strict

 

function OnMouseDown(){

   

    //This will load the level (I've put 1 assuming your level is 1 in your build, but you can (must) change that accordingly to how your build is set up.

    Application.LoadLevel(1);

 

}

Quit button :

#pragma strict

 

function OnMouseDown(){

   

    //This will quit the game.

    Application.Quit();

 

}

so i add them to to the script

No , don’t add this to the scripts, replace it.

oh ok

works great

Nice !

thank u so much sir
pls can i get your contact
email facebook
if u dont mind plss

?

sir can u help me now on a levels script
for each levels