Skip to content
Snippets Groups Projects
Commit 919d0e86 authored by vanessrw's avatar vanessrw
Browse files

add: weapon switching

parent 783222ad
Branches
1 merge request!14Feat/mobs
This diff is collapsed.
...@@ -14,6 +14,7 @@ public class GameInput : MonoBehaviour ...@@ -14,6 +14,7 @@ public class GameInput : MonoBehaviour
[NonSerialized] public KeyCode sprintButton = KeyCode.LeftShift; [NonSerialized] public KeyCode sprintButton = KeyCode.LeftShift;
[NonSerialized] public KeyCode inputToggleButton = KeyCode.LeftControl; [NonSerialized] public KeyCode inputToggleButton = KeyCode.LeftControl;
[NonSerialized] public KeyCode aimToggleButton = KeyCode.E; [NonSerialized] public KeyCode aimToggleButton = KeyCode.E;
[NonSerialized] public KeyCode switchWeaponButton = KeyCode.G;
// Constructor // Constructor
protected void Awake() protected void Awake()
......
fileFormatVersion: 2
guid: 0309cf2d5a9629a4faf26d77d6b8174e
\ No newline at end of file
...@@ -89,4 +89,41 @@ public class Player : PlayerEntity ...@@ -89,4 +89,41 @@ public class Player : PlayerEntity
interactable.InvokeOnInteractAreaExitEvent(); interactable.InvokeOnInteractAreaExitEvent();
stateController.currentInteractables.Remove(interactable); stateController.currentInteractables.Remove(interactable);
} }
// Switches to the next weapon in the list
public void SwitchWeapon()
{
if (WeaponList.Count == 0)
{
Debug.LogWarning("No weapons available.");
return;
}
int currentIndex = WeaponList.IndexOf(Weapon);
int nextIndex = (currentIndex + 1) % WeaponList.Count; // Calculate the index of the next weapon
EquipCurrWeapon(nextIndex);
Debug.Log("Weapon switch SwitchWeapon Player.cs");
}
// Equip a weapon by index
public void EquipCurrWeapon(int index)
{
if (index >= 0 && index < WeaponList.Count)
{
WeaponObject newWeapon = WeaponList[index];
Debug.Log($"Equipped weapon: {newWeapon.name}");
if (Weapon != null)
{
Weapon.gameObject.SetActive(false);
}
newWeapon.gameObject.SetActive(true);
}
else
{
Debug.LogWarning($"Invalid weapon index: {index}");
}
}
} }
...@@ -96,6 +96,11 @@ public class PlayerInputController ...@@ -96,6 +96,11 @@ public class PlayerInputController
IInteractable interactable = player.stateController.currentInteractables[player.stateController.currentInteractables.Count - 1]; IInteractable interactable = player.stateController.currentInteractables[player.stateController.currentInteractables.Count - 1];
interactable.Interact(); interactable.Interact();
} }
else if (Input.GetKeyDown(GameInput.Instance.switchWeaponButton))
{
player.SwitchWeapon();
Debug.Log("Weapon switch else if PlayerInputController.cs");
}
} }
private void HandleToggledInputs() private void HandleToggledInputs()
...@@ -116,5 +121,10 @@ public class PlayerInputController ...@@ -116,5 +121,10 @@ public class PlayerInputController
Debug.Log("Player is Deactivating a companion"); Debug.Log("Player is Deactivating a companion");
player.DeactivateCompanion(player.CompanionSelectorIndex); player.DeactivateCompanion(player.CompanionSelectorIndex);
} }
else if (Input.GetKeyDown(GameInput.Instance.switchWeaponButton))
{
player.SwitchWeapon();
Debug.Log("Weapon switch else if PlayerInputController.cs");
}
} }
} }
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment