Search Unity

Problem with eulerAngles

Discussion in 'Scripting' started by Glemau, Feb 8, 2016.

  1. Glemau

    Glemau

    Joined:
    Jul 24, 2015
    Posts:
    37
    Hi,

    I have a problem with using the eulerAngles:
    I have this Script:
    Code (CSharp):
    1. rotation.x += -Input.GetAxis("Mouse Y") * 10f;
    2. rotation.x = Mathf.Clamp(rotation.x, -89f, 50f);
    3. 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
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Assign complete rotation to Cam.eulerAngles, not individual components.
    Code (csharp):
    1.  
    2. Vector3 rotation = Cam.eulerAngles;
    3. rotation.x += -Input.GetAxis("Mouse Y") * 10f;
    4. rotation.x = Mathf.Clamp(rotation.x, -89f, 50f);
    5. Cam.eulerAngles = rotation;
     
  3. Glemau

    Glemau

    Joined:
    Jul 24, 2015
    Posts:
    37
    So i now added another V3 only for the X axis and now it works fine.
    Thanks!