W
W
WasTabon2021-04-23 19:26:15
Unity
WasTabon, 2021-04-23 19:26:15

NullReferenceException when starting the project, although everything is fine?

The object is bound, nothing is included in the trigger
6082f50833d34848736713.png

public class ShopSlot : MonoBehaviour
{
    [SerializeField]
    private GameObject shipPrefab;
    private MoveShip moveShip;

    private void OnTriggerEnter2D(Collider2D coll)
    {
        moveShip = coll.gameObject.GetComponent<MoveShip>();
        moveShip.vector3Slot = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        moveShip.vector3Slot = Vector3.zero;
        Debug.Log(moveShip.vector3Slot);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WasTabon, 2021-04-23
@WasTabon

I did a check on the tag, there are no errors, but it's still interesting because of what it was

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question