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/FreezeThrowAbility.cs

52 lines
1.8 KiB
C#

using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using Unity.Netcode;
using UnityEngine;
[CreateAssetMenu(menuName = "Abilities/FreezeThrow")]
public class FreezeThrowAbility : Ability
{
[Header("FreezeThrow Settings")]
public float projectileSpeed = 10f;
public override void Execute(ServerCharacter character, Vector3 targetPosition)
{
if (!NetworkManager.Singleton.IsServer)
{
Debug.LogError("[FreezeThrowAbility] Execute should only be called on the server.");
return;
}
if (character == null)
{
Debug.LogError("[FreezeThrowAbility] ServerCharacter is null.");
return;
}
// Spawn the projectile
var spawnPosition = character.transform.position + character.transform.forward * 1.5f;
var direction = (targetPosition - spawnPosition).normalized;
GameObject projectileInstance = Instantiate(prefab, spawnPosition, Quaternion.LookRotation(direction));
if (projectileInstance.TryGetComponent(out NetworkObject networkObject))
{
networkObject.Spawn();
if (projectileInstance.TryGetComponent(out FreezeThrowPrefab freezeProjectile))
{
freezeProjectile.Initialize(character, direction, projectileSpeed, abilityDuration);
Debug.Log($"[FreezeThrowAbility] Projectile launched by {character.name}.");
}
else
{
Debug.LogError("[FreezeThrowAbility] The projectile prefab does not have a FreezeProjectile component.");
Destroy(projectileInstance);
}
}
else
{
Debug.LogError("[FreezeThrowAbility] Prefab must have a NetworkObject component.");
Destroy(projectileInstance);
}
}
}