transform.position

in c# the following code:

transform.position.y = 7.0f;
give me this error:

Assets/Scripts/enemy.cs(19,35): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable.

A hand please, i don’t know what’s wrong.

C# and Boo don’t accept changes to single components of properties: you must copy to a variable, change the component and save it back:

Vector3 temp = transform.position; // copy to an auxiliary variable...
temp.y = 7.0f; // modify the component you want in the variable...
transform.position = temp; // and save the modified value

Or you can do:

 transform.position = new Vector3(transform.position.x, 7f, transform.position.z);

To make your object rotate, you need to make a variable which shows that and then put it into a Vector3.

using UnityEngine

public class Example : MonoBehaiviour {
    private float axisY = 7.0f;
    void exampleClass () {
       transform.position = new Vector3 (transform.position.x, axisY, transform.position.z);
    }
}

@chatoxz