I wish to include a score keeper in my game, but I’m having trouble getting a script to modify the text in a textbox in-game.
Whenever I try to edit the text through a script, I receive this error:
“Type ‘UnityEngine.Component’ does not contain a definition for ‘text’ and no extension method ‘text’ of type ‘UnityEngine.Component’ could be found. Are you missing an assembly reference?”
Here’s my current script if anyone’s wondering:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//Spaceholder
public class ScoreUpdate : MonoBehaviour {
private Component ScoreKeeper;
void Start () {
ScoreKeeper = GameObject.Find("ScoreKeeper").GetComponent<Text>();
if (ScoreKeeper == true){
Debug.Log("I found the scorekeeper!");
}
ScoreKeeper.text = "test"; //Test Message
}
void Update () {
//ScoreKeeper.text = "test"; //Not being used.
}
}
If anyone knows what’s wrong, please let me know, a lot of the answers that are already on this site don’t even work for me. Thanks.