Random cube length on instantiate...

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) :smiley:

When you Instantiate, create a new instance of your prefab, or “clone” your “thingy” gameObject. Then create a Vector3 scale that caches the original scale of the clone. Next, change the scale variable on the desired axis or axes, then set your clone’s localScale to the new scale setting.

using UnityEngine;
using System.Collections;

public class GOSpawn : MonoBehaviour 
{
	
	public float delay;
	public GameObject thingy;
	
	void Start () 
	{
		InvokeRepeating("Spawn", delay, delay);
	}
	
	void Spawn () 
	{
		GameObject thingy_clone = Instantiate(thingy, new Vector3(Random.Range(-6, 6), 10, 0), Quaternion.identity) as GameObject;
		Vector3 scale = thingy_clone.transform.localScale;
		scale.x = Random.Range (1, 4);
		thingy_clone.transform.localScale = scale;
	}
}