jeudi 29 janvier 2015

Unity script not doing anything, but dont get any errors either

Hey guys im pretty new to unity and coding in genereal but ive really tried to figure out why this script does not apply. The idea of the script is that is is supposed to spawn an object on a random location on the X-axis within the range +9 to -9 repeatedly, but it just spawn once at the start location of the object.Hope someone can point me in the right direction :) Here is the script, cheers!


using UnityEngine; using System.Collections;



public class SpawnOnXaxis : MonoBehaviour {

public GameObject Goodfood;
public int numToSpawn;
public Vector3 position;

void Awake()
{
Vector3 position = new Vector3(Random.Range(-9.0F, 9.0F), 10.5f, -1); // -9 på Xaxis - +9 ----- Y = 10.5 z = -1
}

void Start()
{
int spawned = 0;

while (spawned < numToSpawn)
{

position = new Vector3(Random.Range(-9.0F, 9.0F), 10.5f, Random.Range(-9.0F, 9.0F));

GameObject tmp = Instantiate(Goodfood, position, Quaternion.identity) as GameObject; // Quaternion.identity betyder "ingen rotation"

spawned++;
System.Threading.Thread.Sleep(500);
}
}


}





Aucun commentaire:

Enregistrer un commentaire