After implementing the different weapon prefabs and bow/mouse aiming, my sword now will only point left and the bow will only move slightly rather than opposing my mouse position if i circle the player.
Character not flipping the sword:
It’s hard to show the mouse cursor/bow issue as screenshots dont capture the cursor. But if its close to the left of the character, the bow is on the left side of the character, if the cursor is far to the left of the character, the bow is on the right of the character.
The bow does aim correctly if the cursor moves around the edge of my screen, but if it’s close to the player it doesnt seem to behave correctly.
Not sure where i would begin to look at code to troubleshoot this. Any help appreciated
Active Inventory Class:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ActiveInventory : MonoBehaviour
{
private int activeSlotIndexNum = 0;
private PlayerControls playerControls;
private void Awake(){
playerControls = new PlayerControls();
}
private void Start(){
playerControls.Inventory.Keyboard.performed += ctx => ToggleActiveSlot((int)ctx.ReadValue<float>());
ToggleActiveHighlight(0);
}
private void OnEnable(){
playerControls.Enable();
}
private void ToggleActiveSlot(int numValue){
ToggleActiveHighlight(numValue - 1);
}
private void ToggleActiveHighlight(int indexNum){
activeSlotIndexNum = indexNum;
foreach(Transform inventorySlot in this.transform) {
{
inventorySlot.GetChild(0).gameObject.SetActive(false);
}
this.transform.GetChild(indexNum).GetChild(0).gameObject.SetActive(true);
ChangeActiveWeapon();
}
}
private void ChangeActiveWeapon(){
if(ActiveWeapon.Instance.CurrentActiveWeapon != null)
{
Destroy(ActiveWeapon.Instance.CurrentActiveWeapon.gameObject);
}
if(!transform.GetChild(activeSlotIndexNum).GetComponentInChildren<InventorySlot>())
{
ActiveWeapon.Instance.WeaponNull();
return;
}
GameObject weaponToSpawn = transform.GetChild(activeSlotIndexNum).
GetComponentInChildren<InventorySlot>().GetWeaponInfo().weaponPrefab;
GameObject newWeapon = Instantiate(weaponToSpawn, ActiveWeapon.Instance.transform.position, Quaternion.identity);
ActiveWeapon.Instance.transform.rotation = Quaternion.Euler(0,0,0);
newWeapon.transform.parent = ActiveWeapon.Instance.transform;
ActiveWeapon.Instance.NewWeapon(newWeapon.GetComponent<MonoBehaviour>());
}
}