Fixed some stuff

dev-hazim
Hazim Bin Ijaz 2 weeks ago
parent 3576ce23af
commit e738cf0a05

@ -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

@ -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();
@ -59,38 +75,64 @@ public class AbilitySystem : NetworkBehaviour
}
private void ManageVectorFenceIndicator()
{
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 PositionWallIndicator()
private void UpdateWallIndicatorPosition()
{
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);
wallIndicator.transform.position = hit.point; // Update position to follow the mouse
}
}
private void StartWallPlacement()
{
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out RaycastHit hit))
{
wallSpawnPosition = hit.point; // Save spawn position
isWallPlacementStarted = true;
Debug.Log($"[AbilitySystem] Wall placement started at {wallSpawnPosition}");
}
}
private void RotateWallIndicator()
{
if (isWallPlacementStarted && wallIndicator != null)
{
float mouseX = Input.GetAxis("Mouse X");
wallIndicator.transform.Rotate(Vector3.up, mouseX);
wallIndicator.transform.Rotate(Vector3.up, mouseX * wallRotationSpeed); // Rotate Y-axis based on mouse movement
}
}
private void ManageStandardAbilityIndicator()
{
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.");
}

Loading…
Cancel
Save