- Home /
Use gameObject as position
I have this script:
#pragma strict
var prefabToSpawn : GameObject;
var spawnPlace : Vector3;
var isTrue = true;
var rndNum : int;
function Start () {
while(isTrue) {
yield WaitForSeconds(1);
yield WaitForSeconds (rndNum);
RunEvent();
}
}
function Update () {
rndNum = Random.Range(0, 3);
print(rndNum);
}
function RunEvent () {
Instantiate(prefabToSpawn, spawnPlace, Quaternion.identity);
}
What the script does, is that it spawns a object with some random time apart. But the spawner the script is attached to moves while it spawnes, but the place that my object spawns doesn't follow this "spawner object". And thats because i assigned a position that they need to spawn: var spawnPlace : Vector3; Is it possibly to say: var spawnPlace : GameObject; So that the position they spawn is where the gameobject i?
@NinjaRubberBand - please format your code for future posts. After pasting your code, select it and use the 101/010 button. I did it for you this time.
Answer by NikoBusiness · Dec 01, 2014 at 10:12 PM
make public var spawnOBJ : GameObject; and add the spawner object at its reference in the inspector. and the Instantiate(prefabToSpawn, spawnOBJ.transform.position, Quaternion.identity);
Your answer
Follow this Question
Related Questions
[Solved] How to get non repeating random positions? 5 Answers
Object's sprite and collider are not at same position as transform 1 Answer
gameobject generates sometimes on previous position 1 Answer
Compare Position of two gameobjects and if true, do nothing, help me please! 1 Answer
Locating Position of Object not Working? 2 Answers