Sorry if I word this incorrectly, but how do I register if a raycast hit returns null ?
At the moment I’m simply using a crude method of having an invisible wall behind the player (lowerWall) and having the raycast register that if it hits nothing else.
if(Physics.Raycast(shootingRay, out hit, attackDistance))
{
if(hit.collider.tag == "LowerWall")
{
Debug.Log("Searching");
}
else
if(hit.collider.tag == "ShieldCube")
{
Debug.Log("Blocked");
canFire = false;
}
else
if(hit.collider.tag == "Enemy")
{
canFire = true;
InvaderFireWeapon();
}
if(hit.collider.tag == "Player")
{
canFire = true;
InvaderFireWeapon();
}
}
Is there a way programmatically to check if a raycast doesn’t actually hit anything
I tried -
if(hit.collider == null)
{
Debug.Log("Searching");
}
This didn’t throw up any errors, but it didn’t actually do anything either.
Any help greatly appreciated.
???