Hi, I’m trying to Instantiate a prefab at a randomly generated position, but it always appears at the position the prefab had, when I originally created it. I already looked for similar questions, but I coulnd’t find any…
Anyways, here is my current code:
using UnityEngine;
using System.Collections;
public class AppleManage : MonoBehaviour {
public GameObject Apple;
void Start ()
{
InvokeRepeating ("Spawn", 3f, 3f);
}
void Spawn ()
{
int s = Random.Range (1, 4);
if (s == 1)
{
Vector3 position = new Vector3(Random.Range(-4.5F, 4.5F), Random.Range(-4.5F, 4.5F), 5.5F);
Instantiate(Apple, position, Quaternion.identity);
}
if (s == 2)
{
Vector3 position = new Vector3(5.5F, Random.Range(-4.5F, 4.5F), Random.Range(-4.5F, 4.5F));
Instantiate(Apple, position, Quaternion.identity);
}
if (s == 3)
{
Vector3 position = new Vector3(Random.Range (-4.5F, 4.5F), 5.5F, Random.Range(-4.5F, 4.5F));
Instantiate(Apple, position, Quaternion.identity);
}
}
}