EVERYTHING
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user