From e738cf0a058837eca764a0a78df4e5f100d061f6 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Fri, 3 Jan 2025 17:26:18 +0500 Subject: [PATCH] Fixed some stuff --- .../Action/Abilities/Vector Fence.asset | 2 +- Assets/Scripts/Gameplay/AbilitySystem.cs | 79 ++++++++++++++----- 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/Assets/GameData/Action/Abilities/Vector Fence.asset b/Assets/GameData/Action/Abilities/Vector Fence.asset index 6d809ec..a9a569d 100644 --- a/Assets/GameData/Action/Abilities/Vector Fence.asset +++ b/Assets/GameData/Action/Abilities/Vector Fence.asset @@ -16,7 +16,7 @@ MonoBehaviour: abilityName: Vector Fence abilityRadius: 0 abilityMagnitude: 0 - abilityDuration: 10 + abilityDuration: 5 abilityCooldownTime: 3 prefab: {fileID: 9694722736535169, guid: 9b94ed8895919e84aa669628b0761eaf, type: 3} wallLength: 5 diff --git a/Assets/Scripts/Gameplay/AbilitySystem.cs b/Assets/Scripts/Gameplay/AbilitySystem.cs index 45a97b1..805dfb7 100644 --- a/Assets/Scripts/Gameplay/AbilitySystem.cs +++ b/Assets/Scripts/Gameplay/AbilitySystem.cs @@ -18,6 +18,12 @@ public class AbilitySystem : NetworkBehaviour [SerializeField] private GameObject currentAbilityIndicator; [SerializeField] private GameObject wallIndicator; + [Header("Wall Placement Settings")] + [SerializeField] private float wallRotationSpeed = 2f; + + private Vector3 wallSpawnPosition; + private bool isWallPlacementStarted = false; + void Update() { HandleAbilityMode(); @@ -27,25 +33,35 @@ public class AbilitySystem : NetworkBehaviour { if (isAbilityActive) { - if (activeAbility.abilityKey == GameDataSource.Instance.VectorWallAbilityKey) + if (activeAbility.abilityKey == "VectorFence") { ManageVectorFenceIndicator(); + + if (!isWallPlacementStarted) + { + UpdateWallIndicatorPosition(); // Follow the mouse when ability is activated + } + if (Input.GetMouseButtonDown(0)) { - PositionWallIndicator(); + StartWallPlacement(); } - if (Input.GetMouseButton(0)) + + if (Input.GetMouseButton(0) && isWallPlacementStarted) { - RotateWallIndicator(); + RotateWallIndicator(); // Rotate while holding LMB } - if (Input.GetMouseButtonUp(0)) + + if (Input.GetMouseButtonUp(0) && isWallPlacementStarted) { - UseActiveAbility(); + UseActiveAbility(); // Place the wall when LMB is released + isWallPlacementStarted = false; } } else { ManageStandardAbilityIndicator(); + if (Input.GetMouseButtonDown(0)) { UseActiveAbility(); @@ -60,37 +76,63 @@ public class AbilitySystem : NetworkBehaviour private void ManageVectorFenceIndicator() { - wallIndicator.SetActive(true); - currentAbilityIndicator.SetActive(false); + if (wallIndicator != null) + { + wallIndicator.SetActive(true); + currentAbilityIndicator.SetActive(false); + + // Apply ability-specific scale to the wall indicator + if (activeAbility is VectorFenceAbility vectorFence) + { + wallIndicator.transform.localScale = new Vector3(vectorFence.wallLength, vectorFence.wallHeight, vectorFence.wallWidth); + } + } + } + + private void UpdateWallIndicatorPosition() + { + if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit)) + { + wallIndicator.transform.position = hit.point; // Update position to follow the mouse + } } - private void PositionWallIndicator() + private void StartWallPlacement() { if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit)) { - wallIndicator.transform.position = hit.point; - var vectorFence = (VectorFenceAbility)activeAbility; - wallIndicator.transform.localScale = new Vector3(vectorFence.wallLength, vectorFence.wallHeight, vectorFence.wallWidth); + wallSpawnPosition = hit.point; // Save spawn position + isWallPlacementStarted = true; + Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}"); } } private void RotateWallIndicator() { - float mouseX = Input.GetAxis("Mouse X"); - wallIndicator.transform.Rotate(Vector3.up, mouseX); + if (isWallPlacementStarted && wallIndicator != null) + { + float mouseX = Input.GetAxis("Mouse X"); + wallIndicator.transform.Rotate(Vector3.up, mouseX * wallRotationSpeed); // Rotate Y-axis based on mouse movement + } } private void ManageStandardAbilityIndicator() { - currentAbilityIndicator.SetActive(true); - wallIndicator.SetActive(false); + if (currentAbilityIndicator != null) + { + currentAbilityIndicator.SetActive(true); + } + if (wallIndicator != null) + { + wallIndicator.SetActive(false); + } UpdateIndicatorPosition(); } private void DeactivateIndicators() { - currentAbilityIndicator.SetActive(false); - wallIndicator.SetActive(false); + if (currentAbilityIndicator != null) currentAbilityIndicator.SetActive(false); + if (wallIndicator != null) wallIndicator.SetActive(false); } public void ActivateAbilityByKey(string key) @@ -137,6 +179,7 @@ public class AbilitySystem : NetworkBehaviour { isAbilityActive = false; activeAbility = null; + isWallPlacementStarted = false; Debug.Log("Ability mode deactivated."); }