ProjectZ/Assets/Scripts/Network/ComponentsSync.cs

70 lines
1.6 KiB
C#
Raw Normal View History

2024-02-19 21:00:36 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using StarterAssets;
using Player;
public class ComponentsSync : NetworkBehaviour
{
public List<GameObject> objects;
public List<MonoBehaviour> scripts;
public SkinnedMeshRenderer playerModel;
public Interactions interactions;
public CharacterController controller;
// public SpectatorController specController;
public PersonController persController;
public bool alive = true;
void Start()
{
persController.OnLiveState += OnLiveState;
if (!isLocalPlayer)
{
foreach (var gameObject in objects)
{
gameObject.SetActive(false);
}
foreach (var script in scripts)
{
script.enabled = false;
}
}
else
{
playerModel.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
alive = persController.Alive;
}
}
private void OnLiveState(Pawn player, bool state)
{
alive = state;
if (isLocalPlayer)
{
interactions.enabled = alive;
controller.enabled = alive;
// specController.enabled = alive;
}
else
{
if (alive)
{
playerModel.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
}
else
{
playerModel.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.ShadowsOnly;
}
}
}
}