Im new using Unity, i was doing an FPS Game (following some tutorials) but when i made an “weapon switching” this bug happened
when i use my secondary weapon, i cant move my camera down or up, only left and right
i can normally shoot, aim, and etc, just cant move my camera down or up
So, i thought it was an coding issue and i changed the code to the “Brackeys” one, it worked the same and with the same problem, can someone help me?
the code im using for it follows below
(my discord: ⎝⧹Tales-Kun ⧸⎠╱.#4679)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
public int selectedWeapon = 0;
// Start is called before the first frame update
void Start()
{
SelectWeapon();
}
// Update is called once per frame
void Update()
{
int previousSelectedWeapon = selectedWeapon;
if (Input.GetAxis("Mouse ScrollWheel") >0f)
{
if (selectedWeapon >= transform.childCount - 1)
selectedWeapon = 0;
else
selectedWeapon++;
}
if (Input.GetAxis("Mouse ScrollWheel") < 0f)
{
if (selectedWeapon <= transform.childCount - 1)
selectedWeapon = transform.childCount -1;
else
selectedWeapon--;
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
selectedWeapon = 0;
}
if (Input.GetKeyDown(KeyCode.Alpha2) && transform.childCount >= 2)
{
selectedWeapon = 1;
}
if (previousSelectedWeapon != selectedWeapon)
{
SelectWeapon();
}
}
void SelectWeapon()
{
int i = 0;
foreach (Transform weapon in transform)
{
if (i == selectedWeapon)
weapon.gameObject.SetActive(true);
else
weapon.gameObject.SetActive(false);
i++;
}
}
}
