Assets/Score.cs(19,25): error CS0120: An object reference is required to access non-static member `UnityEngine.Component.guiText'
using UnityEngine; using System.Collections;
public class Score : MonoBehaviour {
static public int score = 0;
static public int highScore = 0;
static public void AddPoint(){
score++;
if(score>highScore){
highScore = score;
}
}
void Update () {
GUIText.text = "Score: " + score + "\nHigh Score: " + highScore;**ERROR**
}
}
Answer by Jessespike · Mar 18, 2016 at 05:22 PM
You've posted a couple of questions regarding the same error. The error is saying you need an object reference. You seem to understand what an int is, so I'll try to explain with that.
int = 4; // this will fail because the variable int hasn't been declared
int score = 4; // this works, because "score" is the int
It's the same idea with GUIText. You need to declare what GUIText is. Hook it up in the inspector.
public GUIText guiText;
void Update() {
guiText.text = "Score: ...";
}
In general, I initially could not put gui text, because it is not otorazhalsya, in general, and put another now I do not know what to do :(
Your answer
![](https://koobas.hobune.stream/wayback/20220612072350im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Top Down 2D, facing direction bools 0 Answers
2D Top-Down Shooter Glitch With Camera Focus 0 Answers
I use prefabs in prefabs and when I correct the root prefab of child prefabs, items don't correct. 0 Answers
2D Mobile: How to mask a gameObject with another gameObject (with soft edges) 0 Answers
Walking around a sprite 1 Answer