Tuesday, December 11, 2012

Unity how to change text mesh when pushing button

Let say you want to change the value of text mesh by 10 everytime you pressing a button,

below is what you should do

1. Open Unity, add text mesh let say "myText"
2. Create a new javascript and attach it to your button
3. On your javascript put


private var myCredit : int=100;
private var myTextMesh :TextMesh

function awake()
{
      myTextMesh=transform.Find("myText").GetComponent(TextMesh);

}


function OnMouseDown()  //when pressing button
{
      myCredit += 10; 
      myTextMesh.text =myCredit.ToString();
}

No comments:

Post a Comment