using UnityEngine; public class Player : MonoBehaviour { private int mValue = Random.Range( 0, 10 ); }
このように変数初期化子でRandom.Range関数を使用すると
下記のようなエラーが発生します
RandomRangeInt can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
変数の初期化でRandom.Range関数を使用したい場合は
Awake関数やStart関数で呼び出す必要があります
using UnityEngine; public class Player : MonoBehaviour { private int mValue; private void Awake() { mValue = Random.Range( 0, 10 ); } }