テキストにを用意し、画面に出した後、スクリプトで表示内容を変更します。
1.プロジェクト作成
プロジェクト名:Unity01、2Dを選択します。
2.テキストを配置し、表示してみる
GameProject -> UI -> TEXT を選択し、配置する
Canvasの中にTextができた。EventSystemも追加されている。
配置されたテキストがどこにあるか確認(Altを押しながらマウスで探す)
見つけたら、Canvasの中に入れておく。文字列を「Hello World!!」に変更
動かしてみる
3.スクリプト作成
Text -> Add Component -> New Script -> Name を「TextController」に変更、C#を確認し、Create and Add
コードを作成
インスタンスとして、
public Text Textbox;
update関数に追加
Textbox.text = "Hello World! (From Code)";
全体
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class TextController : MonoBehaviour { | |
public Text Textbox; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
Textbox.text = "Hello World! (From Code)"; | |
} | |
} |
保存してみるとTextboxという項目が追加されている
隣の小さなボタンを押して紐付けします。
これで動かしてみると、コードで書いた文字列が表示されます 参考
http://hololenshelpwebsite.com/Blog/EntryId/3/Unity-5-Hello-World
0 件のコメント:
コメントを投稿