Unity上でcreateから作れるから、TextとかButtonとかUI下にあるオブジェクトはGameObjectの亜種だと勘違いしてました...
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Initialize : MonoBehaviour {
public Canvas canvas;
// Use this for initialization
void Start () {
Text target = null;
foreach (Transform child in canvas.transform){
if(child.name == "Main Title"){
target = child.gameObject;
target.text = "AAAAAAA";
} else if (child.name == "Sub Title") {
target = child.gameObject;
target.text = "BBBBBBB";
}
}
}
// Update is called once per frame
void Update () {
}
}
と書いたら華麗にエラーが起きたので、どうした物かと悩んでいたんですが、TextのInspectorをよく見た所、
(Script)なる文言が...
という事は、UIオブジェクト群って コンポーネント だったんですね...恥ずかしい...
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Initialize : MonoBehaviour {
public Canvas canvas;
// Use this for initialization
void Start () {
Text target = null;
foreach (Transform child in canvas.transform){
if(child.name == "Main Title"){
target = child.gameObject.GetComponent<Text>();
target.text = "AAAAAAA";
} else if (child.name == "Sub Title") {
target = child.gameObject.GetComponent<Text>();
target.text = "BBBBBBB";
}
}
}
// Update is called once per frame
void Update () {
}
}
無事"Main Title"と"Sub Title" Textの文言の変更出来た!