Open EloiStree opened 4 weeks ago
🤖
using UnityEngine;
public class CheckLayerMask : MonoBehaviour
{
// Assign your LayerMask in the inspector or programmatically
public LayerMask layerMask;
// Check if the GameObject is within the LayerMask
public bool IsInLayerMask(GameObject obj, LayerMask mask)
{
// Shift the layer of the GameObject and check if it's in the LayerMask
return (mask.value & (1 << obj.layer)) != 0;
}
// Example usage
void Start()
{
GameObject obj = gameObject; // The GameObject you want to check
if (IsInLayerMask(obj, layerMask))
{
Debug.Log($"{obj.name} is in the LayerMask.");
}
else
{
Debug.Log($"{obj.name} is NOT in the LayerMask.");
}
}
}
https://docs.unity3d.com/ScriptReference/LayerMask.html