Okay. I got one script ’ script in singleton pattern . I have an issue with the other script . I need to know what I need to change on the script call Game . I need to access the GameManagerSingleton from the game script is what I am saying. I know need to make some changes on it . I don’t know how to approach this situation. I made some changes on the game script so I can access the singleton script . But I am getting a lot of errors. The game script access and keep track of the score and time . I just need the score code on the game script to be corrected. Here are my scripts :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GameManagerSingleton : MonoBehaviour
{
public static GameManagerSingleton instance = null;
public int score = 0;
Text text;
void Awake()
{
if (instance != null && instance != this)
Destroy(gameObject); // Ensures that there aren't multiple Singletons
instance = this;
}
}
public class ScoreObject
{
void IncreaseScore()
{
GameManagerSingleton.instance.score += pointsEarned;
}
void Update()
{
text.text = "Score : " + score;
}
}
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Collections;
public class Game : MonoBehavior
{
private GameManagerSingleton GameManagerSingletonScript _ Instance
private myclock MyClockScript;
private void Start ()
{
GameManagerSingleton = GetComponent<GameManagerSingleton>();
myClock = GetComponent<MyClockScript>();
}
void Update ()
{
if (myClock != NULL && GameManagerSingleton != NULL)
{
// need somthing here
}
if (m_leftTime >= 0 && 50 < GameManagerSingleton.score)
{
SceneManager.LoadScene("time");
}
}
}