「Unity/UIText」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
編集の要約なし
15行目: 15行目:
  using UnityEngine.UI;
  using UnityEngine.UI;
  public class MessageText : MonoBehaviour {
  public class MessageText : MonoBehaviour {
public string text = "";
public string text = "";
// Use this for initialization
// Use this for initialization
void Start () {
void Start () {
}
}
// Update is called once per frame
// Update is called once per frame
void Update () {
void Update () {
this.GetComponent<Text>().text = text;
this.GetComponent<Text>().text = text;
}
}
  }
  }
#呼び出しのButtonイベント内に
#呼び出しのButtonイベント内に
  this.GetComponent<MessageText>().text = "Click!";
  this.GetComponent<MessageText>().text = "Click!";
などを追加
などを追加

2017年3月17日 (金) 09:31時点における版

Text配置

  1. GameObject/UI/Textを選択すると"New Text"がCanvas上に設置される
  2. そのまま再生
  • Project Saveだと消えるかも。File/Sence Saveしておかないと。

TextのScript制御

  1. UITextを配置
  2. UITextを選択してinspectorを開く
  3. 一番上のTextというところをTextMessageなどと変えてエンターキーを押す(エンターを押さないと変更できない)
  4. AddComponentでNewScriptを選択して"MessageText"と入れてMessageText.csファイルを作る
  5. 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;
	}
}
  1. 呼び出しのButtonイベント内に
this.GetComponent<MessageText>().text = "Click!";

などを追加