- Home /
How do I get my scene to load in Unity3d C#
I have problem my scene wont load up. My scene is suppose to load up when the timer reaches zero and score can't below number I have set. Meaning if I have the number set for 50 in the game and the number is lower than 50 then and timer reaches zero the number don't change. I have a timer script , score script , and the script I am accessing from . I also change the operators and I still couldn't get the scenes to change.
Here are my scripts :
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement; public class Game : MonoBehaviour {
private MyClockScript myClock; void Start () { myClock = GetComponent(); }
// Update is called once per frame
void Update () {
if (myClock.m_leftTime <= 0 || GameManagerSingleton.score > 50)
{
SceneManager.LoadScene("T");
}
}
}
using UnityEngine; using System.Collections; using UnityEngine.UI; public class MyClockScript : MonoBehaviour { public int Minutes = 0; public int Seconds = 0;
private Text m_text;
public float m_leftTime;
private void Awake()
{
m_text = GetComponent<Text>();
m_leftTime = GetInitialTime();
}
public void Update()
{
if (m_leftTime > 0f)
{
// Update countdown clock
m_leftTime -= Time.deltaTime;
Minutes = GetLeftMinutes();
Seconds = GetLeftSeconds();
// Show current clock
if (m_leftTime > 0f)
{
m_text.text = "Time : " + Minutes + ":" + Seconds.ToString("00");
}
else
{
// The countdown clock has finished
m_text.text = "Time : 0:00";
}
}
}
private float GetInitialTime()
{
return Minutes * 60f + Seconds;
}
private int GetLeftMinutes()
{
return Mathf.FloorToInt(m_leftTime / 60f);
}
private int GetLeftSeconds()
{
return Mathf.FloorToInt(m_leftTime % 60f);
}
}
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class GameManagerSingleton : MonoBehaviour { public static GameManagerSingleton instance = null;
public static int score;
private Text text;
void Awake()
{
text = GetComponent <Text> ();
score = 0;
if (instance != null && instance != this)
Destroy(gameObject); // Ensures that there aren't multiple Singletons
instance = this;
}
void Update()
{
text.text = "Score: " + score;
Debug.Log("Score: " + score);
}
Your answer
Follow this Question
Related Questions
Unity Scene not loading. 1 Answer
Application.LoadLevel obsolete but SceneManager.LoadScene Doesn't work 5 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can I build a scene once and have it be importable? 2 Answers