One of the GameObjects I am using in my game are cubes… But my game depends on cubes being of random lengths, almost like platforms, because my game is a FallDown clone where you have to keep going down or lose. I have a script that generates cubes and spawns them at random coordinates (included below). I also have a cube prefab, which is a generic cube to be spawned. I was thinking, maybe the way to do this is not through a prefab, but through another method I am not aware of.
When the cubes spawn, they move upwards due to directional gravity, giving the illusion of descending.
SCRIPT:
using UnityEngine;
using System.Collections;
public class GOSpawn : MonoBehaviour {
public float delay;
public GameObject thingy;
// Use this for initialization
void Start () {
InvokeRepeating("Spawn", delay, delay);
}
// Update is called once per frame
void Spawn () {
Instantiate(thingy, new Vector3(Random.Range(-6, 6), 10, 0), Quaternion.identity);
}
}
C# plezzz thanks (in advance)