- Home /
Question by
levan1 · Jan 06, 2014 at 06:26 AM ·
scenesubmission
how to submit the coins number to the new scene?
How to submit the number of coins collected by the moment when the time is over and counts down to 0 in my code to the game over scene? and how to display them in the game over scene? give me example, please, if possible
GUI and time:
#pragma strict
var textStyle: GUIStyle;
var skin:GUISkin;
//timer control
private var timer:float;
private var roundUpSeocnds:int;
private var timerText:String;
function Start () {
timer = DataCenter.timerUpdate;
}
function Update () {
timer = timer - Time.deltaTime;
//level faild
if(timer <= 0)
{
//Stop counting when timer is 0
Application.LoadLevel ("Game Win");
timer = 0.0f ;
}
}
function OnGUI ()
{
GUI.skin = skin;
GUI.color = new Color(0.039, 0, 0.145);
var coinNumberName = PlayerCounters.coinCounter;
var coinName = coinNumberName.ToString();
GUI.Label(Rect(45,40,70,250), coinName);
//timer control
roundUpSeocnds = Mathf.CeilToInt(timer);
timerText = roundUpSeocnds.ToString();
GUI.Label (Rect (45,140,70,250), String.Format("{0}", timerText), textStyle);
}
PlyerCounters.js
#pragma strict
static var coinCounter = 0;
function Update () {
if(coinCounter >= 300)
{
Application.LoadLevel ("Game Win");
}
}
function OnTriggerEnter (info : Collider)
{
if(info.transform.name == ("Coin"))
{
coinCounter += 10;
}
}
Comment
Answer by Invertex · Jan 06, 2014 at 06:48 AM
Use "DontDestroyOnLoad" in the script that you store the stats in, so that it carries over to the next scene/level.
http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
In this situation you'd want to use "this.gameObject".
function Awake()
{
DontDestroyOnLoad (this.gameObject);
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Making a Jetpack 3 Answers
terrain wont come up in scene 0 Answers
UnityEngine.Input.GetMouseButton(1)) issue 1 Answer
Unity Serializer Load Question 1 Answer