Added UI and more
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
using TMPro;
|
||||
using Unity.Netcode.Components;
|
||||
using System;
|
||||
|
||||
public class PlayerHealth : NetworkBehaviour
|
||||
@@ -91,7 +91,27 @@ public class PlayerHealth : NetworkBehaviour
|
||||
private void RespawnClientRpc(Vector3 _spawnPosition)
|
||||
{
|
||||
SetPhysicsAndVisualsActive(true);
|
||||
transform.position = _spawnPosition;
|
||||
|
||||
// Позицию задаёт только владелец — он авторитет над NetworkTransform (Owner authority)
|
||||
if (!IsOwner) return;
|
||||
|
||||
TeleportOwner(_spawnPosition);
|
||||
}
|
||||
|
||||
// Телепорт без интерполяции. CharacterController кэширует свою позицию,
|
||||
// поэтому его надо выключить на время установки трансформа.
|
||||
private void TeleportOwner(Vector3 _spawnPosition)
|
||||
{
|
||||
CharacterController _controller = GetComponent<CharacterController>();
|
||||
if (_controller != null) _controller.enabled = false;
|
||||
|
||||
NetworkTransform _netTransform = GetComponent<NetworkTransform>();
|
||||
if (_netTransform != null)
|
||||
_netTransform.Teleport(_spawnPosition, transform.rotation, transform.localScale);
|
||||
else
|
||||
transform.position = _spawnPosition;
|
||||
|
||||
if (_controller != null) _controller.enabled = true;
|
||||
}
|
||||
|
||||
private void SetPhysicsAndVisualsActive(bool _isActive)
|
||||
@@ -101,16 +121,5 @@ public class PlayerHealth : NetworkBehaviour
|
||||
|
||||
foreach (MeshRenderer meshRenderer in GetComponentsInChildren<MeshRenderer>())
|
||||
meshRenderer.enabled = _isActive;
|
||||
|
||||
Rigidbody rigidbody = GetComponent<Rigidbody>();
|
||||
if (rigidbody == null) return;
|
||||
|
||||
rigidbody.isKinematic = !_isActive;
|
||||
|
||||
if (_isActive)
|
||||
{
|
||||
rigidbody.linearVelocity = Vector3.zero;
|
||||
rigidbody.angularVelocity = Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user