I’m not sure why the code below isn’t working as I am using a temp variable. The error is: error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.rotation’. Consider storing the value in a temporary variable
Note that this is just a simplified version of my code, I am not applying the rotation in update in the proper code, but this illustrates the problem.
public class test : MonoBehaviour {
Transform _this_transform;
void Start () {
_this_transform = GetComponent<Transform> ();
}
void Update () {
Vector3 _current_rotation = _this_transform.rotation.eulerAngles;
_current_rotation.x = 0f;
_current_rotation.y = 180f;
_current_rotation.z = 0f;
_this_transform.rotation.eulerAngles = _current_rotation;
}
}
Any advice appreciated, thanks.