|
|
|
using System.Collections;
|
|
|
|
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
|
|
|
|
using UnityEngine;
|
|
|
|
using Unity.Netcode;
|
|
|
|
|
|
|
|
[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 movement
|
|
|
|
character.Movement.StartDash(targetPosition, dashSpeed, dashDuration);
|
|
|
|
|
|
|
|
// Ensure the crowModel exists and has an Animator
|
|
|
|
if (character.crowModel != null && character.crowModel.TryGetComponent<Animator>(out var animator))
|
|
|
|
{
|
|
|
|
Debug.Log("Triggering Dive animation for crow model.");
|
|
|
|
TriggerDiveAnimationClientRpc(character.NetworkObjectId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogError("Crow model is not assigned or is missing an Animator component!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delay spawning the slow zone until after the dash
|
|
|
|
character.StartCoroutine(SpawnSlowZoneAfterDash(character, targetPosition));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// ClientRpc to trigger the Dive animation on all clients.
|
|
|
|
/// </summary>
|
|
|
|
[ClientRpc]
|
|
|
|
private void TriggerDiveAnimationClientRpc(ulong objectId)
|
|
|
|
{
|
|
|
|
if (!NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(objectId, out var netObj))
|
|
|
|
{
|
|
|
|
Debug.LogError($"[Client] NetworkObject with ID {objectId} not found in SpawnedObjects.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netObj.TryGetComponent<Animator>(out var animator))
|
|
|
|
{
|
|
|
|
animator.SetTrigger("Dive");
|
|
|
|
Debug.Log($"[Client] Dive animation triggered for {netObj.name}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogError($"[Client] Animator not found on {netObj.name}.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//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 NetworkAnimator0
|
|
|
|
// if (character.crowModel != null)
|
|
|
|
// {
|
|
|
|
// NetworkAnimator networkAnimator = character.crowModel.GetComponent<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.");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|