How Do I Procedurally Generate Clouds ?

Hello Community!

I am giving procedural generation a crack. the goal is to instantiate planes (clouds) in a random area on screen.

In my case 0 - 480 on the x - axis, and 0 - 360 on the y - axis.

The script i’m using is this.

Script.js:

#pragma strict

var blueCloud : GameObject;
var orangeCloud : GameObject;

var cloudChance : int;

var cloudPosition : Vector3;

var cloudX : float;

var cloudY : float;

function Start () {

   cloudChance = Random.Range (1, 3);
   
if (cloudChance == 1) {

   cloudX = Random.Range(0, 4.8);
   cloudY = Random.Range(0, 3.2);

   cloudPosition = Vector3(cloudX, cloudY, - 0.2);
   
   Instantiate (redCloud, cloudPosition, transform.rotation);
   
}

if (cloudChance == 2) {

   cloudX = Random.Range(0, 4.8);
   cloudY = Random.Range(0, 3.2);

   cloudPosition = Vector3(cloudX, cloudY, - 0.2);
   Instantiate (orangeCloud, cloudPosition, transform.rotation);
   
}

if (cloudChance == 3) {

   cloudX = Random.Range(0, 4.8);
   cloudY = Random.Range(0, 3.2);

   cloudPosition = Vector3(cloudX, cloudY, - 0.2);
   
   Instantiate (blueCloud, cloudPosition, transform.rotation);
   
}

}

But it only Instantiates the plane (cloud) randomly in the top right part of the screen (never behind or underneath the player).

Thanks for the interest so far!

The position property in GUIText and GUITexture is in viewport coordinates: 0,0 is lower left, 1,1 is top right. You must specify valid x and y coordinates (between 0 and 1). The z coordinate sets its depth relative to other GUIText or GUITexture objects (higher z appears over the others). If the GUI element is a child of another object, you must set its position after the instantiation; if the parent object moves, you must set the gui position each Update (any small parent movement shifts the gui object out of screen).