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(); 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; } } } }