Question by
Alsador · Oct 16, 2015 at 10:07 PM ·
instantiatespawningy-axisx-axis
Issues Spawning objects.
So I'm to make a 2D game, and trying to make a script to spawn objects continuously along the Y axis. I would like it so that they spawn with random ranges between certain x co ordinates. I also would like to have the new spawned objects to have a minimum and maximum Y distance between the original. My idea is to have it so when a player passes through a trigger it would cause a clone of the said object with a different X and Y cooridnates.
This is what i have so far but the object doesn't clone at all.
public GameObject Meteor;
// Use this for initialization
void Start () {
GameObject[] Meteor = GameObject.FindGameObjectsWithTag ("Meteor");
}
// Update is called once per frame
void OnTriggerEnter2D(Collider2D collider) {
Debug.Log ("Triggered by" + collider.name);
Vector3 position = transform.position;
position.x = Random.Range (-1.75f, 1.75f);
position.y ++;
if (collider.gameObject.tag == "Player")
{
GameObject meteor = Instantiate(Meteor, transform.position, Quaternion.identity) as GameObject;
}
}
Any help would be greatly appreciated!!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612041601im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy Spawner Help 0 Answers
How to spawn multiple prefabs at different spawn rates 0 Answers
Spawn Prefab based on int value 1 Answer
moving an object in a circular motion based on the parent 1 Answer