I want the rayCast to register all hits except the ones on the player
The player is on Player layer. I used a layerMask and selected all layers except the player but that dint work heres the code im using:
IEnumerator Shoot()
{
RaycastHit2D hit = Physics2D.Raycast(shootOrigin.transform.position , shootOrigin.transform.right , layerMask);
if(hit)
{
Debug.Log(hit.transform.name);
Enemy enemy = hit.transform.GetComponent<Enemy>();
if (enemy != null)
{
enemy.TakeDamage(damage);
}
lineRenderer.SetPosition(0, shootOrigin.transform.position);
lineRenderer.SetPosition(1, hit.point);
}
else
{
lineRenderer.SetPosition(0, shootOrigin.transform.position);
lineRenderer.SetPosition(1, shootOrigin.transform.position + shootOrigin.transform.right * 100);
}
lineRenderer.enabled = true;
yield return new WaitForSeconds(0.02f);
lineRenderer.enabled = false;
}