I’m looking to change the text value of an object by clicking on a different object. I’m not sure what’s wrong. Using Javascript here buddies.
Objects in use:
cubeA with script startButtonScript.js attached
3DText
Script:
var buttonText : TextMesh;
function Start () {
}
function Update () {
}
function OnMouseUpAsButton() {
buttonText.GetComponent.<TextMesh>().text = "Hello World";
}
I’ve applied the script to cubeA in Unity, and drug the 3DText object into the buttonText variable in Unity. Any idea what I’m doing wrong? There’s no actual error in the code, but it’s not working.
Your buttonText is already the TextMesh you are looking for so you wouldnt need to use GetComponent.
Also in UnityScript you dont use GetComponent() you simply put it in the brackets GetComponent(TextMesh).
Also theres one dot too much behind GetComponent in your code.
I’m not sure exactly what was wrong, but I was getting the error, “the variable buttonText doesn’t exist anymore” every time I clicked on the button. I re-drug the object back onto the script, it changed the icon next to it and viola it worked with this small change in code:
Thanks for the clarification Arterie.
buttonText.text = "Hello world";