You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Gameplay/ExecutionerBox.cs

55 lines
1.7 KiB
C#

using UnityEngine;
using Unity.Netcode;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using UnityEngine.SocialPlatforms.Impl;
public class ExecutionerBox : NetworkBehaviour
{
private ServerCharacter _owner;
private Vector3 _endPos;
private float _travelTime;
private float _startTime;
private Vector3 _startPos;
public void Initialize(ServerCharacter owner, Vector3 startPos, Vector3 endPos, float travelTime)
{
_owner = owner;
_startPos = startPos;
_endPos = endPos;
_travelTime = travelTime;
transform.position = startPos;
transform.LookAt(endPos);
_startTime = Time.time;
}
private void Update()
{
if (!IsServer) return;
float journeyProgress = (Time.time - _startTime) / _travelTime;
transform.position = Vector3.Lerp(_startPos, _endPos, journeyProgress);
if (journeyProgress >= 1f)
NetworkObject.Despawn();
}
private void OnTriggerEnter(Collider other)
{
if (!IsServer) return;
if (other.TryGetComponent<ServerCharacter>(out var victim) && victim != _owner)
{
// Get owner client ID before despawning
ulong ownerId = _owner.OwnerClientId;
// Handle score changes
ScoreManager.Instance.AddPlayerScore(ownerId, 10); // Add to owner
ScoreManager.Instance.SubtractPlayerScore(victim.OwnerClientId, 10); // Subtract from victim
Debug.Log($"[ExecutionerBox] Scores updated. " +
$"Owner ({ownerId}) gained 10, " +
$"Victim ({victim.OwnerClientId}) lost 10");
}
}
}