error cs0120 problems

Hey guys,

I’m having a little trouble making my c# code change the text values of a GUIText component. It keeps throwing the following error, no matter how i try:

error CS0120: An object reference is required to acces non-static member ‘UnitEngine.Component.guiText’

The c# file is attached to my GUIText component, and it holds the following code:
using UnityEngine;
using System.Collections;

public class LevelDisplay : MonoBehaviour {
    public static void ShowScore(int sequenceCounter) {

What am i missing?

Thanks in advance…

You don’t appear to have defined the variable guiText and set it to the instance of some GuiTexture component. OR guiText is defined on LevelDisplay but your are trying to access it from a static function.

It might be better to use the Singleton pattern:

    public static LevelDisplay Instance;
   void Awake() 
       Instance = this;

And then you always have the LevelDisplay Instance available to get the guiText.

   LevelDisplay.Instance.guiText.text = "Whatever";