Please help

For example player click on the word, i want the color to stay on instead of going back to the original color. Don’t know if you get what i am asking. For example, initially the color is white, so when player’s mouse over the text, it will turn to blue but when the mouse exit it will turn to the original color “white”, how can i retain the color blue? Because i want to let the player know which alphabets they have clicked.

function OnMouseEnter()
{
guiText.material.color = Color.blue;
}

function OnMouseExit()
{
guiText.material.color = Color.white;
}
Another question is that for example player finish playing level1. But the player instead of proceed to the next level, they click to the main menu. So when they feel like continue the game, i want them to go to level 2 instead of the level 1 that they have already play and complete. How do i solve it?

Thank you :slight_smile:

I think what you can do is put a “boolean” in the script to tell if the button have been pressed or not. For example:

var buttonPressed : boolean = false;

function OnMouseEnter () 
{
     guiText.material.color = Color.blue;
}

function OnMouseExit () 
{
     guiText.material.color = Color.white;
}

function OnMouseUp()
{
	buttonPressed = true;
	
     if(buttonPressed == true)
	 {
	     guiText.material.color = Color.blue;
	 }
	 else
	 {
	     guiText.material.color = Color.white;
	 }
}

Try this, this code have not been tested yet. I think it will work.

for question 2, I dont understand what you want to do, are you saying that when the player finish the 1st level they went back to main menu and from main menu you choose to continue played to level 2.

Hi hizral84,

Thank you for the reply. For the 2nd question, i mean for example, you play a game until certain level then you have to stop to do something else. So when you are going back to the game, you are expecting to be direct to the level you stop instead of restarting from level1.

Are you talking about a LOAD/SAVE GAME system?

In that case you should take a look at :
http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html

Yes. Something like that. Thank Thunderent.

Hi hizral84, it is not working. When i click on the word, it turn blue, but once the mouse left the word, it will turn back to original color (white).

Hello Thunderent, i don’t really understand PlayerPrefs. How do i start doing it? And where should i put this script to?? HELP!! :frowning:

Are you talking about saving only the player’s position…or saving the entire ,stuff’ he did that level(like ,points" gained,kills,etc).

You can save the player position with ArrayPrefs from the Unity Wiki.
http://www.unifycommunity.com/wiki/index.php?title=ArrayPrefs

Just take the PlayerPrefsX.js from there and put it into your Standard Assets folder from your project.If you don’t have a Standard Assets folder,make one,and then you can use something like:

var player : GameObject; 
      function OnTriggerEnter () {
        PlayerPrefsX.SetVector3("PlayerPosition", player.transform.position);
         print("player position saved");
}

Make a cube,make it’s size bigger…and then check the Is Trigger button below the Box Collider.Attach this script onto your created cube.Everytime the player passes through the cube it saves the player’s position…exactly where your cube is.

If you want to load your player position just use:

player.transform.position = PlayerPrefsX.GetVector3("PlayerPosition");

I didn’t test the code…sorry if anything from here is wrong,please correct me…i’m a beginner too^^.

add a check in the OnMouseExit():
if(!buttonPressed )

Hello Thunderent, actually i am doing a puzzle game. So i do not have to store the player position or score. Perhap i might need to store those words that the player formed. To be exact, i don’t think i need to store any value. I just want to make sure that the player are in the correct level. You get what i trying to say?

can you show me you script please(for the button).

for the load save thing, I think you could do a game manager for that, make something like this.

1.If finish level 1, save state for level 1 finished.
2.At main menu make a state that tell if level 1 is finished auto load to level 2.

Hi hizral84, it work properly. I need to do some checking on the onMouseExit(). But as i am doing puzzle games, for example player form word “A T E”, the words will disappear and being replaced by a new words AEO. how do i reset the click button. I don’t know if you understand. For example, when player click A T E, it will remain blue color right? So once the correct word formation, the A T E will be disappear and being replaced by A E O. But A E O is still remain blue whereas it should be in white.‘’’

1.If finish level 1, save state for level 1 finished.
2.At main menu make a state that tell if level 1 is finished auto load to level 2
→ i don’t really understand this. Could you explain in details with code xample? thank you

var buttonPressed : boolean = false;

function OnMouseEnter () 
{
     guiText.material.color = Color.blue;
}

function OnMouseExit () 
{
    if (!buttonPressed) guiText.material.color = Color.white;
}

function OnMouseUp()
{
	buttonPressed = !buttonPressed;
	
     if(buttonPressed)
	 {
	     guiText.material.color = Color.blue;
	 }
	 else
	 {
	     guiText.material.color = Color.white;
	 }
}

Just some minor changes.

I think for this one you need to do some checklist code, so to check if the word you have cross out is in the checklist or not, per say you click “A T E”, so if there is ATE in the checklist return the color back to white. never done this before but in theory I would do it like this.

for the level state example, this is just a pseudo code. you might need to change it:

this script inside level1 to tell that level1 is completed

static var levelOneIsDone : boolean = false;

function Update()
{
	levelOneIsDone = true;
	
	if(levelOneIsDone == true)
	{
		//return to main menu
	}
	else
	{
		//do something else
	}
}

and then this script inside main menu and check if level1 is completed.

function Update()
{
	if("nameOfTheScript".levelOneIsDone == true) //to check if level1 is complete
	{
		//jump to level2 instead
	}
	else
	{
		//do something else
	}
}

haha forget about that, thanks for reminding me.

Hello hizral84, thank for the help. I will try the level state problem later.

your welcome.