Camera not Following Inspector's Value (Transform) When Play

Hi,
Sorry for this, but I’m newbie. I swear.

I was learning by following the “Project” provided by Unity. The “Roll-a-Ball”. Was learning the camera. I followed the video, but with different value. Then, found a problem.

So, with the inspector, I set the Position value with:

Because I wanted the camera view be like this:

But, when I tested it, I hit Play, the value changed by itself:

And the camera position:

The Main Camera is independent in the hierarchy.
And the script for the camera:

using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {

    public GameObject player;
    private Vector3 offset;

    void Start () {

        offset = transform.position;
   
    }

    void Update () {

        transform.position = player.transform.position + offset;

    }
}

So, how to use the value I set and not changing when I hit play?
Thanks,
I’m noob, hope you understand XD

Not sure if I get the point but from what I understand your script will only work as expected if the Player has the initial position 0, 0, 0.

So, I have to assign the value within the .cs file? Not in Unity?

I thinnk i found the problem.

Since i set the transform.position = player.transform.position + offset;

so the Z position of the camera is + the Z position of the playerObject. So when I hit play, ofcourse it’s getting far from the GameObject because the Z value of player.transform.position != 0 - it’s about -8,3. So when entering the Play mode, the transform.position value of the camera isn’t the way I set it. It became -18 ( -10 + (-8) = 18).

Thanks anyway :smile: