This is my code:
public static void Awake()
{
Vector3 position1 = new Vector3(Random.Range(220.9f, 281.8f), -1.23f, Random.Range(282.25f, 295.43f));
Vector3 position2 = new Vector3(Random.Range(281.8f, 315.6f), -1.23f, Random.Range(222.8f, 200.67f));
Vector3 position3= new Vector3(Random.Range(280.1f, 223.8f), -1.23f, Random.Range(222.8f, 200.7f));
Vector3 position4= new Vector3(Random.Range(214.8f, 197f), -1.23f, Random.Range(222.7f, 287.91f));
}
public static void Spawn1()
{
Instantiate (GameObject.FindWithTag("enemy"), position1, Quaternion.identity);
}
public static void Spawn3()
{
Instantiate (GameObject.FindWithTag("enemy"), position2, Quaternion.identity);
}
public static void Spawn3()
{
Instantiate (GameObject.FindWithTag("enemy"), position3, Quaternion.identity);
}
public static void Spawn4()
{
Instantiate (GameObject.FindWithTag("enemy"), position4, Quaternion.identity);
}
Before writing this code, the Vector3 variables where not in the Awake function, but when I run the script I get an error saying that I need to put the Vector3 Variables into an Awake function.
So now, when I call one function (Spawn1(),Spawn2(), etc…) I get an error saying that I can’t acces the Vector3 variables because I need to turn them static. The problem is that Unity doesn’t let me write static / public before
Vector3 position1 = new Vector3(Random.Range(220.9f, 281.8f), -1.23f, Random.Range(282.25f, 295.43f));
Thanks and sorry for my English :P.
EDIT: I had to put the variabels into the Awake function because the Random.Range can’t be called from MonoBehaviour.