The title might be a little hard to understand so basically this is what I want to do:
I have a GUIText object and I want to put a script on a GameObject (cube). This script will have a variable like var EnemyName = "";
I want to put that script on that GameObject (cube), so I can set a particular text for the GUIText object through the inspector for the cube. I will be doing this for more than one GameObject.
I’m doing it in C# and I can’t get it right, I’m getting this error all the time:
error CS1955: The member `UnityEngine.GUIText.text’ cannot be used as method or delegate
Here’s my code
[System.Serializable]
public class ViewScrollZoom : MonoBehaviour {
public GUIText debugger;
void Start() {
}
void Update () {
if(Input.touchCount == 1){
debugger.text("Touching screen now");
}
}
EDITED
Sorry for being stupid. I was trying to figure it out for at least an hour, and finally saw it in front of my eyes… The good part is that I couldn’t find this error referenced anywhere so I’ll just leave it here for future intelligent crowd…
It should be debugger.text = "Clicking with mouse left ";
Here's an untested JS version of what you could do:
var label : GUIText;
var enemyName = "";
function Update() {
label.text = enemyName;
}
You'd put that script on your cube and assign your GUIText to the variable Label in the Inspector. After that the GUItext will always equal the enemyName variable on the cube.