Files
ggj2026/Assets/Scripts/TrickCollisionManager.cs
T
2026-02-01 14:19:40 -06:00

55 lines
1.5 KiB
C#

using UnityEngine;
public class TrickCollisionManager : MonoBehaviour
{
[SerializeField] private string trickLayerName = "Trick";
[SerializeField] private string playerLayerName = "Player";
[SerializeField] private string treatLayerName = "Treat";
[SerializeField] private string destroyTag = "Destroy";
private bool initialized;
private void Awake()
{
Initialize();
}
private void Initialize()
{
if (initialized)
{
return;
}
var trickLayer = LayerMask.NameToLayer(trickLayerName);
if (trickLayer == -1)
{
Debug.LogWarning("Trick layer not found. Create a layer named 'Trick' and assign it to Trick prefab.");
return;
}
Physics2D.IgnoreLayerCollision(trickLayer, trickLayer, true);
IgnoreLayerPair(trickLayer, playerLayerName);
IgnoreLayerPair(trickLayer, treatLayerName);
initialized = true;
}
private void IgnoreLayerPair(int trickLayer, string otherLayerName)
{
var otherLayer = LayerMask.NameToLayer(otherLayerName);
if (otherLayer == -1)
{
Debug.LogWarning($"Layer '{otherLayerName}' not found. Configure it if you want Trick to ignore collisions with it.");
return;
}
Physics2D.IgnoreLayerCollision(trickLayer, otherLayer, true);
}
private void onTriggerEnter2D(Collider2D destroy){
if (destroy.CompareTag(destroyTag))
{
Destroy(gameObject);
}
}
}