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 ‘playerCtrl’ on game object ‘player’.See “Script Serialization” page in the Unity Manual for further details.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spawn_point : MonoBehaviour
{
public GameObject pr_wall;
public GameObject pb_wall;
public GameObject pg_wall;
private float interval = Random.Range(1.0f, 2.0f);
private Vector3 heigt_wall;
// Start is called before the first frame update
void Awake()
{
heigt_wall = new Vector3(0f, Random.Range(-3, 4), 0f);
}
IEnumerator Start()
{
int i = 0;
while (true)
{
/*Instantiate(pr_wall, transform.position, transform.rotation);
Instantiate(pb_wall, transform.position, transform.rotation);
Instantiate(pg_wall, transform.position, transform.rotation);*/
if (i / 3 == 1)
{
Instantiate(pr_wall, transform.position=heigt_wall, transform.rotation);
}
if (i / 3 == 2)
{
Instantiate(pb_wall, transform.position = heigt_wall, transform.rotation);
}
if (i / 3 == 0)
{
Instantiate(pg_wall, transform.position = heigt_wall, transform.rotation);
}
i++;
yield return new WaitForSeconds(interval);
}
}
// Update is called once per frame
void Update()
{
}
}