Glemau
February 8, 2016, 4:35pm
1
Hi,
I have a problem with using the eulerAngles:
I have this Script:
rotation.x += -Input.GetAxis("Mouse Y") * 10f;
rotation.x = Mathf.Clamp(rotation.x, -89f, 50f);
Cam.eulerAngles.x = rotation.x;
And this Error:
Assets/Scripts/Move.cs(35,29): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.eulerAngles’. Consider storing the value in a temporary variable
Would be awesome if you could help me!
~glemau
Assign complete rotation to Cam.eulerAngles, not individual components.
Vector3 rotation = Cam.eulerAngles;
rotation.x += -Input.GetAxis("Mouse Y") * 10f;
rotation.x = Mathf.Clamp(rotation.x, -89f, 50f);
Cam.eulerAngles = rotation;
Glemau
February 8, 2016, 4:45pm
3
ThermalFusion:
Assign complete rotation to Cam.eulerAngles, not individual components.
Vector3 rotation = Cam.eulerAngles;
rotation.x += -Input.GetAxis("Mouse Y") * 10f;
rotation.x = Mathf.Clamp(rotation.x, -89f, 50f);
Cam.eulerAngles = rotation;
So i now added another V3 only for the X axis and now it works fine.
Thanks!