Unity Image要素からファイル名を取得する
ちょっと躓いたのでメモ
Image image;
public Text text;
public void Start() {
image = GetComponent<Image> ();
text.text = image.sprite.name;
}
spriteを一回指定しないといけないのね...
gameobjectはcomponentではないのね
MissingComponentException: There is no 'GameObject' attached to the "ThirdSaitenButton" game object, but a script is trying to access it.
のようにエラーが出たが解決したため備忘用
スクリプトから自身のgameObjectを扱いたい場合は
var obj = this.GetComponent <GameObject>();
では取得できず、
var obj = gameObject と入力で取得できる。
あくまでGameObjectはコンポーネントではないため
this.Getcomponent<>()は使用できない。
参考
There is no GameObject attached to this GameObject - Unity Answers