How to make simple achievement system.
Im thinking in making a bool “Achieved = true” after a if statement saying that I hit something for first time and also having a SendMessage to another script. So that message will be “Achived”. And on the other script it wil be :
//JavaScript
var Achieved = false;
function Achieved(){
if(Achieved == true)
OnGui()
}
function OnGui(){
GUI.Box(Rect(1,1,Screen.widht,Screen.height),"Achievement Earned!")
if(GUI.Button(Rect(10,10,20,10),"Close"))
//Closes the GUI.Box
}
I dont know if this works or not I´m not good in sccripting just 13. Also to close the GUI.Box what do I use there? Help me please. And one thing - So when I hit something the script will send a message to the other script and the GUI.Box should pop-up saying that we Earned the achievement and if I click the button the Box should close.
You don’t call OnGUI: all On… functions are events called by Unity when the specified action happens (like OnTriggerEnter, for instance). You should instead use a boolean variable to control whether the GUI items will appear or not - like this:
private var achieved = false;
private var showGui = false;
function Achieved(){
if (achieved == false){ // if not achieved yet...
achieved = true; // set flag achieved to true...
showGui = true; // and show GUI items
}
}
function OnGUI(){
if (showGui){ // if GUI enabled by showGui:
// draw the controls:
GUI.Box(Rect(1,1,Screen.widht,Screen.height),"Achievement Earned!")
if(GUI.Button(Rect(10,10,20,10),"Close")){
showGui = false; // set showGui to false to hide these GUI items
}
}
}
Here is a free tutorial on Unity Cookie makes a complete simple achievement system.1
Also you caint put a OnGUI function in an if statement it is called anyways and will give an error.