
유니티 개발 창에서 실행하면 rain 프리팹이 생성될 때 마다 다음과 같은 예외가 표시됩니다.
UnityException: RandomRangeInt is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'rain'.
See "Script Serialization" page in the Unity Manual for further details.
게임의 작동에는 아무 문제 없습니다.
이런 예외가 왜 나오는 건가요?
게임 자체는 실행되니까 그냥 넘어가도 되는 문제입니까?
만약 위의 예외를 해결하려면 어떻게 해야합니?

작성한 코드 및 에러 메세지
작성한 GameManager의 코드는 아래와 같습니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject rain;
public static GameManager I;
public Text scoreText;
int totalScore;
void Awake()
{
I = this;
}
void Start()
{
InvokeRepeating("makeRain", 1.0f, 0.5f);
}
void Update()
{
}
void makeRain()
{
Instantiate(rain);
}
public void AddScore(int score)
{
totalScore += score;
scoreText.text = totalScore.ToString();
}
}
예외의 상세는 아래와 같습니다.
UnityException: RandomRangeInt is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'rain'.
See "Script Serialization" page in the Unity Manual for further details.
UnityEngine.Random.Range (System.Int32 minInclusive, System.Int32 maxExclusive) (at <913bb12059fd4cef8da5cc94ad2f0933>:0)
rain..ctor () (at Assets/Scripts/rain.cs:7)
UnityEngine.Object:Instantiate(GameObject)
GameManager:makeRain() (at Assets/Scripts/GameManager.cs:26)
