Whenever I try to generate a random number between the two parameters it gives me the error:
Random.Range(float, float) cannot be accessed with an instance reference; qualify it with a type name instead
I am new to Unity, so any help would be greatly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
public GameObject enemy;
float randx;
float randy;
Vector2 whereToSpawn;
public float spawnRate = 2f;
float nextSpawn = 0f;
Random random = new Random();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Time.time > nextSpawn)
{
nextSpawn = Time.time + spawnRate;
randx = random.Range(-1.408f, 1.232f);
randy = random.Range(0.776f, 1.232f);
whereToSpawn = new Vector2 (randx, randy);
Instantiate(enemy, whereToSpawn, Quaternion.identity);
}
}
}