「Unity/UIText」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
|||
| 15行目: | 15行目: | ||
using UnityEngine.UI; | using UnityEngine.UI; | ||
public class MessageText : MonoBehaviour { | public class MessageText : MonoBehaviour { | ||
public string text = ""; | |||
// Use this for initialization | |||
void Start () { | |||
} | |||
// Update is called once per frame | |||
void Update () { | |||
this.GetComponent<Text>().text = text; | |||
} | |||
} | } | ||
#呼び出しのButtonイベント内に | #呼び出しのButtonイベント内に | ||
this.GetComponent<MessageText>().text = "Click!"; | this.GetComponent<MessageText>().text = "Click!"; | ||
などを追加 | などを追加 | ||
2017年3月17日 (金) 09:31時点における版
Text配置
- GameObject/UI/Textを選択すると"New Text"がCanvas上に設置される
- そのまま再生
- Project Saveだと消えるかも。File/Sence Saveしておかないと。
TextのScript制御
- UITextを配置
- UITextを選択してinspectorを開く
- 一番上のTextというところをTextMessageなどと変えてエンターキーを押す(エンターを押さないと変更できない)
- AddComponentでNewScriptを選択して"MessageText"と入れてMessageText.csファイルを作る
- MessageText.csに以下の通りに
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MessageText : MonoBehaviour {
public string text = "";
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.GetComponent<Text>().text = text;
}
}
- 呼び出しのButtonイベント内に
this.GetComponent<MessageText>().text = "Click!";
などを追加