Randomly changing a hazard's scale while the game is running.

How do I change the scale of My hazards in the middle of the game? I have 6 different hazards that I want to appear on the screen in many different sizes at the same time. Currently, the hazards are coming out all the same size, which is not what I want. Here is My code:

		while (levelCount <= hazardsCount) 

			levelCount += 2;

					for (int i = 0; i < levelCount; i++) {

// This is the random scale that I have ranging from 0.3 to 1.2
scale = Random.Range (0.3f, 1.2f);
GameObject hazard = hazards [Random.Range (0, hazards.Length)];
Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
Quaternion spawnRotation = Quaternion.identity;

// Here is where I assign the scale(x,y,z)
// transform.root.transform.localScale.x=scale;
// transform.root.transform.localScale.y = scale;
// transform.root.transform.localScale.z = scale;

// Here I create My hazards
Instantiate (hazard, spawnPosition, spawnRotation);
yield return new WaitForSeconds (spawnWait);
yield return new WaitForSeconds (waveWait);

					if (gameOver) {
						RestartText.text = "Press 'R' for Restart.";
						restart = true;

Any suggestions on how I can do this?

You need to set hazard.localScale = Vector3.one * scale; instead of transform.root.transform.localScale ...

Cheers, Oskar


Thank you for the suggestion. Since I am learning C# on my own, it is an uphill battle.

Well I tried what you suggested and was not able to get the script to compile with no errors. I am currently on using this to adjust the scale:

GetComponent()transform.localeScale * scale;

HOWEVER it seems that GetObject does not have transform within it.

What am I doing wrong?