Question by
Antrozwastaken · Sep 26, 2016 at 11:11 AM ·
raycastingraycasthit2d
Raycast not detecting the floor gameObject
I don't know why my raycast isn't detecting any object.
The Error: NullReferenceException: Object reference not set to an instance of an object
The Code:
void Update()
{
RaycastHit hit;
Physics.Raycast(new Vector3(transform.position.x, transform.position.y, transform.position.z - 1), new Vector3(transform.position.x, transform.position.y, transform.position.z + 1), out hit);
if (hit.collider != null)
{
Debug.Log("Hit");
}
Debug.DrawLine(new Vector3(transform.position.x, transform.position.y, transform.position.z-1), new Vector3(transform.position.x, transform.position.y, transform.position.z + 1), Color.yellow);
}
Comment
Your answer
Follow this Question
Related Questions
Select from multiple character to move 0 Answers
Raycast2D hit.point is zero ? 0 Answers
Rigidbody blocking raycasts 2D 0 Answers
Is there any way how to do raycasts like this? 0 Answers
I can't get Raycasting in 2D to work, what am I missing? 1 Answer