- Home /
Points and lifes C#
Hi! Im "new" in Unity and I ony once hear about do not destroy on load. So like in topic I need help with makeing points and lifes in game, its working like quiz in 3D and You have on trigger enter and when you go in to the trigger correct you will get points and go to other scene with another question. And when you get into the wrong answer you will lose life, to time when you will get 0 lifes you will be moved to main scene. (points should be showed on gui) Thx for help anyway!
(sory for bad ENG)
$$anonymous$$ake a Game manager script to hold lifes and points, put it in a GameObject create a prefab with it and put it in all scenes. in the script create a static field of the same type of the script, in the script awake method check if the static variable is null, if is set its value to "this", if not is null,check if is equals to "this" if is "DontDestroyOnLoad(this)" else "Destroy(this)".
Since the explanation is a little bit hard to follow, I quickly Typed it out:
public static Game$$anonymous$$anager game$$anonymous$$anager;
void Awake ()
{
if (game$$anonymous$$anager == null) {
game$$anonymous$$anager = this;
}else{
if(game$$anonymous$$anager == this){
DontDestroyOnLoad (this);
}else{
Destroy(this);
}
}
}
Your answer

Follow this Question
Related Questions
Next LEVEL Load Problem. 2 Answers
Don'tDestroyOnLoad issue, please help :( 1 Answer
DontDestroyOnLoad Game Score/Lives 1 Answer
Save points from one scene to another? 3 Answers
how can i make my character to be on another scene? 1 Answer