I am writing a script that will change a plants size and rotation based on a variable that the player can change, I wrote it so that I could attach it to the plants prefab and then it would work automatically at start, it worked perfect at first but then I just tried to change an objects y scale to make it taller but that made it so that everything dissapears, I am 100% sure without a doubt that it is the first 3 if statements in Start() but I am not that good with Vector3’s so I do not know how else to change only the x y and z coordinates.
using UnityEngine;
using System.Collections;
public class RandomFlowerSize : MonoBehaviour {
//The flower we will manipulate.
[Header("Object To Manipulate")]
public GameObject objectToChange;
//Allows you to change sizes and shapes and rotations of the game object.
[Header("What values should be changed")]
public bool sizeX = true;
public bool sizeY = true;
public bool sizeZ = true;
public bool rotateX = true;
public bool rotateY = true;
public bool rotateZ = true;
[Header("Rotation values")]
[Range(0, 360)]
public float xRotation = 10f;
[Range(0, 360)]
public float yRotation = 10f;
[Range(0, 360)]
public float zRotation = 10f;
//Variable that control the flowers min and max size.
[Header("Size values")]
[Range(0, 1)]
public float minXSize = 0.4f;
[Range(0, 2)]
public float maxXSize = 1.0f;
[Range(0, 1)]
public float minYSize = 0.4f;
[Range(0, 2)]
public float maxYSize = 1.0f;
[Range(0, 1)]
public float minZSize = 0.4f;
[Range(0, 2)]
public float maxZSize = 1.0f;
void Start () {
if (sizeX == true) {
var randomXSize = Random.Range(minXSize, maxXSize);
objectToChange.transform.localScale = new Vector3 (randomXSize, 0, 0);
}
if (sizeX == true) {
var randomYSize = Random.Range(minYSize, maxYSize);
objectToChange.transform.localScale = new Vector3(0, randomYSize, 0);
}
if (sizeZ == true) {
var randomZSize = Random.Range(minZSize, maxZSize);
objectToChange.transform.localScale = new Vector3(0, 0, randomZSize);
}
if (rotateX == true) {
var randomRotationX = Random.Range(0, xRotation);
objectToChange.transform.Rotate(randomRotationX, 0, 0);
}
if (rotateY == true) {
var randomRotationY = Random.Range(0, yRotation);
objectToChange.transform.Rotate(0, randomRotationY, 0);
}
if (rotateZ == true) {
var randomRotationZ = Random.Range(0, zRotation);
objectToChange.transform.Rotate(0, 0, randomRotationZ);
}
}
}