Version: 2018.4
public TextAnchor alignment ;

説明

テキスト自身の RectTransform との相対的な位置取り。

This is the positioning of the Text relative to its RectTransform. You can alter this via script or in the Inspector of a Text component using the buttons in the Alignment section.

//Create a Text GameObject by going to Create>UI>Text. Attach this script to the GameObject to see it working.

using UnityEngine; using UnityEngine.UI;

public class UITextAlignment : MonoBehaviour { Text m_Text;

void Start() { //Fetch the Text Component m_Text = GetComponent<Text>(); //Switch the Text alignment to the middle m_Text.alignment = TextAnchor.MiddleCenter; }

//This is a legacy function used for an instant demonstration. See the UI Tutorials pages and UI Section of the manual for more information on creating your own buttons etc. void OnGUI() { //Press this Button to change the Text alignment to the lower right if (GUI.Button(new Rect(0, 0, 100, 40), "Lower Right")) { m_Text.alignment = TextAnchor.LowerRight; }

//Press this Button to change the Text alignment to the upper left if (GUI.Button(new Rect(150, 0, 100, 40), "Upper Left")) { m_Text.alignment = TextAnchor.UpperLeft; } } }