- Home /
Question by
mistergreen2016 · Jul 27, 2017 at 03:25 PM ·
staticnon-static
How to use non static field in static member?
I have an Event manger with static members. The static members will update scores, sound and such. The problem is I need to update the text of UI text field which is public only. Of course this will throw an non static member error. How do I get around this?
public class EventManager : MonoBehaviour {
public delegate void DieAction(GameObject obj);
public static event DieAction OnDie;
public Text score;
public static int scoreCount = 0;
public static void DieDispatch(GameObject obj)
{
if (obj.tag == "coin")
{
//play sound, add score etc....
score.text = "SCORE:" + scoreCount.ToString();
}
if (OnDie != null)
{
//event for anybody subscribing
OnDie(obj);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Calling non-static from static function C# 2 Answers
Why is my kill method not running the score system method call? 1 Answer
Static vs Non-static functions and variables 1 Answer
An instance of type "x" is required to access non-static variable "y" 2 Answers
Adding x amount of energy in another Class issue C# 1 Answer