Question by
importguru88 · Jun 10, 2016 at 08:37 PM ·
scripting problemerrorsingleton
error CS0176: Static member `GameManagerSingleton.score' cannot be accessed with an instance reference, qualify it with a type name instead
I had made some changes on my script and I gotten one error. I trying to access the score script along with another script . Here is my scripts:
using UnityEngine; using System.Collections; 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.instance.score > 50)
{
SceneManager.LoadScene("I");
}
}
}
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);
}
}
Comment
Please format your code properly
Did you google the error code? Because it's extremely common and well documented
Answer by importguru88 · Jun 10, 2016 at 09:12 PM
Okay. I figure it out I just delete instantce . I got no errors.