- Home /
Question by
VeryAnnoyingCat · Oct 16, 2020 at 11:34 AM ·
2draycastlayermask
Raycast 2D not ignoring layer
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject == player)
{
hit = Physics2D.Raycast(transform.position, (player.transform.position - transform.position).normalized, 8, ignoreRaycast);
if (hit.transform.gameObject == player)
{
enemyScript1.enemyState = 1;
}
}
}
The innermost if stameent does not return anything.
The ignoreRaycast is a manually selected public LayerMask.
Comment
Best Answer
Answer by NoahDaNerd · Oct 16, 2020 at 01:31 PM
The LayerMask parameter is what the raycast should hit, not what it should ignore.