Hello all,
I have a script that goes through all the objects with the tag “VehicleComponent” and then adds the object’s position, rotation and scale to lists storing information about the object. However, the float for the object’s position keeps changing to values near to the object’s actual y position (usually within 3 either way), but not the exact value. The object is always stationary and when I make each object print it’s position every frame, it shows that the object is indeed stationary.
Here is the relevant code:
class VehicleComponents {
public enum Types {Cube, Wheel};
public static List<Vector3> localPosition = new List<Vector3> ();
public static List<Quaternion> localRotation = new List<Quaternion> ();
public static List<Vector3> localScale = new List<Vector3> ();
public static List<Types> type = new List<Types> ();
}
public void Save () {
GameObject[] _vehicleComponents = GameObject.FindGameObjectsWithTag ("VehicleComponent");
foreach (GameObject vehicleComponent in _vehicleComponents) {
VehicleComponents.localPosition.Add (vehicleComponent.transform.position);
VehicleComponents.localRotation.Add (vehicleComponent.transform.rotation);
VehicleComponents.localScale.Add (vehicleComponent.transform.localScale);
if (vehicleComponent.transform.name == "Cube(Clone)") {
VehicleComponents.type.Add (VehicleComponents.Types.Cube);
} else {
VehicleComponents.type.Add (VehicleComponents.Types.Wheel);
}
}
}
Does anyone have any suggestions of what might be the cause and how to fix the problem?
Thanks in advance