次のコードがあります。エディタのテキストコンポーネントをno_livesに参照しました。 gamemanager(シングルトン)は以前にシーンをインスタンス化しています。 debug.log()はコンソールに5を表示します。しかし、テキストを設定しようとすると、参照はオブジェクトのインスタンスに設定されません。何故ですか?Unity3D C# - テキストUI
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class level1_script : MonoBehaviour {
public Text no_lives;
// Use this for initialization
void Start() {
no_lives = GetComponent<Text>();
}
// Update is called once per frame
void Update() {
int lives_n = gamemanager.lives_f();
Debug.Log (lives_n);
no_lives.text = lives_n + " x";
}
}
'no_lives = GetComponent work –
Dawnkeeper
'Start()'が 'Update'の前に呼び出され、GetComponentが実際に値を' no_lives'に設定していることは確かですか?また、 'lives_n'を' lives_n.ToString()+ "x" ' – Nkosi