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.
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
3 weeks ago
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
||
|
using UnityEngine;
|
||
|
using Unity.Netcode;
|
||
|
|
||
|
public class FreezeThrowPrefab : NetworkBehaviour
|
||
|
{
|
||
|
private Vector3 direction;
|
||
|
private float speed;
|
||
|
private float freezeDuration;
|
||
|
private ServerCharacter owner;
|
||
|
|
||
|
public void Initialize(ServerCharacter character, Vector3 direction, float speed, float freezeDuration)
|
||
|
{
|
||
|
this.owner = character;
|
||
|
this.direction = direction.normalized;
|
||
|
this.speed = speed;
|
||
|
this.freezeDuration = freezeDuration;
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (IsServer)
|
||
|
{
|
||
|
transform.position += direction * speed * Time.deltaTime;
|
||
|
|
||
|
// Check for collision or expiry
|
||
|
if (Vector3.Distance(transform.position, owner.transform.position) > 20f)
|
||
|
{
|
||
|
NetworkObject.Despawn();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
if (!IsServer) return;
|
||
|
|
||
|
if (other.TryGetComponent(out ServerCharacter target))
|
||
|
{
|
||
|
if (target != owner)
|
||
|
{
|
||
|
Debug.Log($"[FreezeProjectile] Hit {target.name}. Applying freeze for {freezeDuration} seconds.");
|
||
|
target.Freeze(freezeDuration);
|
||
|
NetworkObject.Despawn();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|