Hi
I’m new to this and I could need a little help with my script.
It’s supposed to spawn an object in a random location between the coordinates (1,0.5,1) and (29,0.5,29) and if that object gets destroyed it should spawn a new one in a new random location.
This is the script I have made. It seems that it only spawn the object in the location (0,0,0). A little help would be appreciated.
#pragma strict
function Start () {
}
var gameobject : GameObject;
var location : Vector3 = Vector3(0,0.5,0);
var xaxis : int=15;
var zaxis : int=15;
function Update () {
var xaxis=Random.Range(1,29);
var zaxis=Random.Range(1,29);
var location : Vector3 = Vector3(xaxis, 0.5, zaxis);
if(transform.childCount < 1)spawn();
}
function spawn () {
var Instance : GameObject = Instantiate(gameobject, location, transform.rotation);
Instance.transform.parent = transform;
}