NullReferenceException: Object reference not set to an instance of an object

Hi, I’m a beginner with unity and Visual Studio and I’m trying to work with “Learning C#…” book, but I have a problem that I can’t fix no matter where I look or what I do, can someone help me?

public class CameraBehavior : MonoBehaviour
{
    public Vector3 camOffset = new Vector3(0f, 1.2f, -2.6f);

    private Transform Target;

    void start()
    {
        Target = GameObject.Find("player").transform;
    }

    void LateUpdate()
    {
        this.transform.position = Target.TransformPoint(camOffset);
        this.transform.LookAt(Target);
    }
}

this is my whole code and my error is this:

NullReferenceException: Object reference not set to an instance of an object
CameraBehavior.LateUpdate () (at Assets/Scrips/CameraBehavior.cs:20)

now I’m sure I have a “player” object but somehow it doesn’t find it or something

The error’s in the fourteenth line. Try replacing “position” with “localPosition”.

And make the first letter of the “Start” method’s name uppercase (just to make sure).

It’s Start written as “start” that’s the problem. Unity’s magic methods are case-sensitive!

@SNoteBook the “use localPosition instead of position” advice is absolutely nonsensical. In the best case OP just ignores is, in the worst case you have thoroughly confused someone trying to learn. It’s like telling somebody trying to learn maths that they have forgotten the cheese grater.

Good on you for trying to help people, but don’t just wildly flail about and tell them to do random stuff that you don’t understand?

I’d like to ask you not to blame me senselessly. I know what I write. I had once the same problem as @prototype008 's, and I solved it by replacing “position” (which was more naturally, I thought) with “localPosition”.

Code is not a magic spell. You don’t just replace some word with some other and then it works for reasons beyond man’s ken.

If the camera script either doesn’t have any parent, or has a zeroed parent, localPosition and .position are the same thing. If the camera script has a parent, OP’s code would break if you used the local position, as Target.TransformPoint(offset) gives the world coordinates the camera should be at, and the local position is relative to the parent object.

So that your thing worked when you changed that is irrelevant, you gave the advice without understanding what OP’s code is doing, or how your advice would effect that.

@Baste I’m just sharing my experience. If you have more — good riddance, you’ll help many people!