weapon switch bug

hello every after creating this script i found a bug its when i switch back from key 2 to 1 key 1 one of the weapon donot work

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class switchweopen : MonoBehaviour
{
    public GameObject shotgun;
    public GameObject ak47;
    
    
    void Start()
    {

        shotgun.SetActive(false);
    }

    
    void Update()
    {
        
        if (Input.GetKey(KeyCode.Alpha1))
        {           
            ak47.SetActive(true);
            shotgun.SetActive(false);
        }

        if (Input.GetKey(KeyCode.Alpha2))
        {
            ak47.SetActive(false);
            shotgun.SetActive(true);
        }
    }
}

Can you define “Do not work”? Like the object is not being set to active correctly?

Syes i have it the same way and it did not work mabye i should change hte relaod script

Maybe it’s because you are using GetKey that calls your action repeatedly while you are holding the button and your should be using GetKeyDown that acts like a simple button press.