So I am making a pokemon clone in unity.
For this project I need to know if you can walk somewhere. I don’t want to use box colliders since it looks buggy.
So I have got this so far:
if (Input.GetKey(KeyCode.UpArrow) && isMoving == false)
{
bool disableMove = false;
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.up, 0.1F);
if (hit != null)
{
if (hit.collider.gameObject.tag == "collision")
{
disableMove = true;
}
}
if (!disableMove)
{
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector2(transform.position.x, transform.position.y + 1);
}
disableMove = false;
}
this gives me a Nullreference on
if (hit.collider.gameObject.tag == "collision")
I am not sure how to solve this.
what am I missing?