can someone help me? (noob problem)

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++;
        }
    }

   
}

A possible explanation is that camera movement controls - somehow - are attached to the 1st weapon. So when you disable it, it disables camera control.

Beyond that it is not quite possible to tell what’s wrong without debugging your project.

If the official script has the same problem then the problem has nothing to do with that script. Like @neginfinity mentioned we would need to see more of the project to be able to determine the problem. Starting with what other scripts are attached to the weapon that is being disabled as well as any child objects as they will be disabled too.

1 Like

(image to help understand)
Well, my movement script is attached to my “FPS Controller”
and my weapon manager to the “Weapon Holder”, the guns are only childs inside it, my code allows to enable one and disable the another

but there is literally no diferrence between the weapons, the only thing that changes is the actual gun model, the scripts and everything are literally Ctrl+C and Ctrl+V

the error isn’t on the weapon itself, because if i change the order of them on the scene this bug happens with the another gun (who was normal)

5414604--550167--upload_2020-1-27_23-19-8.png

Sure, but something else could be referencing one of those and not the other. If changing the order of the guns has the same bug occur with a different object then something like this is going on.

Show us the contents of the Inspector for one of your guns.