Files
2026-06-01 17:19:55 +02:00

48 lines
866 B
C#

using Photon.Pun;
using UnityEngine;
public class SetLayerIfOwned : MonoBehaviour
{
[Header("Layer Name")]
public string localLayerName = "FP";
private int targetLayer;
private bool shouldApply;
private void Awake()
{
PhotonView componentInParent = GetComponentInParent<PhotonView>();
if (componentInParent != null && componentInParent.IsMine)
{
targetLayer = LayerMask.NameToLayer(localLayerName);
if (targetLayer == -1)
{
Debug.LogError("Layer not found: " + localLayerName);
return;
}
shouldApply = true;
SetDirectChildrenLayer();
}
}
private void Update()
{
if (shouldApply)
{
SetDirectChildrenLayer();
}
}
private void SetDirectChildrenLayer()
{
foreach (Transform item in base.transform)
{
if (item.gameObject.layer != targetLayer)
{
item.gameObject.layer = targetLayer;
}
}
}
}