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

66 lines
2.2 KiB
C#

using System.Collections;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
using UnityEngine;
using Unity.Netcode;
using Unity.Netcode.Components;
[CreateAssetMenu(menuName = "Abilities/DashNCrash")]
public class DashNCrashAbility : Ability
{
[Header("Dash Settings")]
public float dashSpeed = 10f;
public float dashDuration = 0.5f;
public override void Execute(ServerCharacter character, Vector3 targetPosition, Vector3 targetRotation)
{
Debug.Log($"Executing DashNCrash for character {character.OwnerClientId} at {targetPosition}.");
// Start the dash
character.Movement.StartDash(targetPosition, dashSpeed, dashDuration);
// Ensure the crowModel exists and has a NetworkAnimator
if (character.crowModel != null)
{
NetworkAnimator networkAnimator = character.crowModel.GetComponentInChildren<NetworkAnimator>();
if (networkAnimator != null)
{
Debug.Log("Triggering Dive animation for crow model.");
networkAnimator.SetTrigger("Dive");
}
else
{
Debug.LogError("NetworkAnimator component missing on crow model!");
}
}
else
{
Debug.LogError("Crow model is not assigned!");
}
// Delay spawning the slow zone until after the dash
character.StartCoroutine(SpawnSlowZoneAfterDash(character, targetPosition));
}
private IEnumerator SpawnSlowZoneAfterDash(ServerCharacter character, Vector3 position)
{
yield return new WaitForSeconds(dashDuration + 0.25f);
// Spawn the slow zone prefab at the dash's end position
var prefab = GetPrefab();
if (prefab != null)
{
GameObject instance = Instantiate(prefab, character.transform.position, Quaternion.identity);
var networkObject = instance.GetComponent<NetworkObject>();
if (networkObject != null)
{
networkObject.Spawn();
Debug.Log($"Slow Zone spawned at {position}.");
}
else
{
Debug.LogError("Slow Zone prefab must have a NetworkObject component.");
}
}
}
}