i am making an fps and i want to have a menu with access to differect weapons. it is also going to be multiplayer at some point. what is the best way to do that. I was thinking different scripts with different guns. what do you think? weapons code
using UnityEngine;
public class SC_WeaponManager : MonoBehaviour
{
public Camera playerCamera;
public SC_Weapon Rifle;
public SC_Weapon Sub;
public SC_Weapon Shotgun;
public SC_Weapon Rocketlauncher;
public SC_Weapon gernade;
[HideInInspector]
public SC_Weapon selectedWeapon;
// Start is called before the first frame update
void Start()
{
//At the start we enable the primary weapon and disable the secondary
Rifle.ActivateWeapon(true);
Sub.ActivateWeapon(false);
Shotgun.ActivateWeapon(false);
Rocketlauncher.ActivateWeapon(false);
gernade.ActivateWeapon(false);
selectedWeapon = Rifle;
Rifle.manager = this;
Sub.manager = this;
Shotgun.manager = this;
Rocketlauncher.manager = this;
gernade.manager = this;
}
// Update is called once per frame
void Update()
{
//Select secondary weapon when pressing 1
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Rifle.ActivateWeapon(true);
Shotgun.ActivateWeapon(false);
Rocketlauncher.ActivateWeapon(false);
Sub.ActivateWeapon(false);
gernade.ActivateWeapon(false);
selectedWeapon = Sub;
}
//Select primary weapon when pressing 2
if (Input.GetKeyDown(KeyCode.Alpha2))
{
Rifle.ActivateWeapon(true);
Sub.ActivateWeapon(false);
Shotgun.ActivateWeapon(false);
Rocketlauncher.ActivateWeapon(false);
gernade.ActivateWeapon(false);
selectedWeapon = Rifle;
}
{
if (Input.GetKeyDown(KeyCode.Alpha3))
{
Rifle.ActivateWeapon(false);
Sub.ActivateWeapon(false);
Rocketlauncher.ActivateWeapon(false);
Shotgun.ActivateWeapon(true);
gernade.ActivateWeapon(false);
selectedWeapon = Shotgun;
}
{
if (Input.GetKeyDown(KeyCode.Alpha4))
{
Rifle.ActivateWeapon(false);
Sub.ActivateWeapon(false);
Rocketlauncher.ActivateWeapon(true);
Shotgun.ActivateWeapon(false);
gernade.ActivateWeapon(false);
selectedWeapon = Rocketlauncher;
}
}
if (Input.GetKeyDown(KeyCode.Alpha5))
{
Rifle.ActivateWeapon(false);
Sub.ActivateWeapon(false);
Rocketlauncher.ActivateWeapon(true);
Shotgun.ActivateWeapon(false);
gernade.ActivateWeapon(true);
selectedWeapon = gernade;
}
}
}
}