Can't Make Raycast Ignore a Layer

I have an object that is constantly right in front of the player, and now I’ve added in an ability for the player to make enemies stop moving by pointing at them with Raycast. I therefore need to make the Raycast coming from the player ignore the object in front of him to make sure the ray won’t just collide with it. I’ve given this object its own layer (layer 10), but the Raycast still collides with it.

This is my code. What have I done wrong?

var Enemy : Transform;
var targetScript01 : FreezeEnemy = Enemy.GetComponent(FreezeEnemy);

var fwd = transform.TransformDirection (Vector3.forward);
var hitInfo : RaycastHit = new RaycastHit();

function Update ()
{
	var mask : LayerMask = 10;
	var fwd = (Enemy.position - transform.position).normalized;
	
	Debug.DrawRay(transform.position + Vector3(0, 1, 0), fwd, Color.red);
	if(Physics.Raycast(transform.position + Vector3(0, 1, 0), fwd, hitInfo, mask.value))
	{
		
		if (hitInfo.collider.gameObject.tag == ("Enemy"))
		{
			targetScript01.Spotted02 = true;
		}
		else
		{
			targetScript01.Spotted02 = false;
		}
		
            }
        }

The Physics.Raycast function takes a bitmask, where each bit determines if a layer will be ignored or not.

so you need to change “var mask : LayerMask = 10;” to “var mask : LayerMask = 1 << 10;

here you could find more details: Unity - Manual: Layers


sorry, I was wrong,“var mask : LayerMask = 1 << 10;” set whick layer would be raycasted.
Hellium’s answer is right.

Be careful, if you want to ignore the layer 10, you will have to use the bitwise NOT Operator (~)

var mask : LayerMask = ~(1 << 10);

However, I would suggest you to put the ennemies in a specific layer, and to make a raycast only in this new layer. Otherwise, your raycast could intersect other elements in your scene (ground, walls, …) and return “yes” even if no ennemy are in front of your player. This way, you won’t have to check the tag condition hitInfo.collider.gameObject.tag == ("Enemy"))

I found a way around it. Since the object in front of the player is only seen by the Raycast exactly when pointing at an enemy, I simply made it a trigger as well.