Question by
knowlife4 · Jul 23, 2017 at 06:47 AM ·
javascriptinstantiatespawn
Having trouble Instantiating.
I'm trying to make a machine that spawns in robots, but it is Instantiating them under the map, at some random location.
#pragma strict
var Points : Transform[];
var Robots : GameObject[];
var AmountOfRobots : int;
var AddToHeight : float;
var Rate : float;
var Range : float;
static var Player : Transform;
static var CurrentAmount : int;
function Start () {
InvokeRepeating("Spawn", 0, Rate);
Player = GameObject.FindGameObjectWithTag("PlayerBox").transform;
}
function Spawn () {
if(Vector3.Distance(Player.position, transform.position) < Range && CurrentAmount <= AmountOfRobots){var Robot = Instantiate(Robots[Random.Range(0, Robots.Length - 1)], Points[Random.Range(0, Points.Length - 1)].position + new Vector3(0,AddToHeight,0), Quaternion.identity); CurrentAmount += 1;}
}
It just makes no sense why it would be doing this!
Comment