M
M
markanez2021-07-09 19:05:49
3D
markanez, 2021-07-09 19:05:49

NullReferenceException: Object reference not set to an instance of an object how to solve?

NullReferenceException: Object reference not set to an instance of an object How to solve?

I copied the entire script from the unity documentation
https://docs.unity3d.com/ru/530/ScriptReference/In...
Script:

public GameObject Ammo;
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray))
                Instantiate(Ammo, transform.position, transform.rotation);
        }
    }


How to solve the error?

PS I want to shoot

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Spartanec33, 2021-07-09
@markanez

Most likely, Ammo was not assigned to the inspector

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question