Justin
Justin

Reputation: 315

How to edit text position in Unity with C#

I want to move text in my game with C# but I am not sure how to get a hold of the actual text nor do I know how to move it's position.

How can this be achieved?

Upvotes: 0

Views: 17766

Answers (2)

Ares Li
Ares Li

Reputation: 613

Are you trying to move your position of the text by using script? Is your text using the UI system of Unity or it is an image/sprite?

You could do something like: For UI text:

Text yourText = Gameobject.Find("the name of your text gameobject").GetComponent<Text>();

yourText.transform.position = new Vector3(posX,posY,posZ);//where posX Y Z is the position where you want to put your text.

If the text you mentioned is a sprite/image, you can use the similar way:

Gameobject yourText = Gameobject.Find("the name of your text gameobject").GetComponent<GameObject>();

yourText.transform.position = new Vector3(posX,posY,posZ);//where posX Y Z is the position where you want to put your text.

Hope this is helpful...

Upvotes: 5

Frohlich
Frohlich

Reputation: 963

As you told that you are trying to make a 2D game I'll assume you are using Unity 5 and trying to use new UI system so you can learn it's mechanics here on video lessons and here on the manual about it. The API references are here to evolve after learn the NUI system's basics.

If you are trying to use GUIText component please let us know because it's a bit different.

If my assumption is wrong and you are not using unity 4.6+ with new UI system you may have something like OnGUI(){blah} on your script and there you are trying to move your text. So let us know this king of details because it is huge different from another ones that I mentioned above.

Upvotes: 0

Related Questions