- Home /
Question by
andreyazbyn · Sep 26, 2015 at 06:46 AM ·
c#multiplayernetworkplayerweaponchangingswitch scenes
Multiplayer frendly weapon select screen
I have a scene where you can select weapons and atatchments. the current way how i switch the weapons is using DontDestroyOnLoad and SetActive and . How can I make it so that it works in multiplayer(the player gets spawned by the network manager) this is the weapon switching script
using UnityEngine;
using System.Collections;
public class NewWeaponSwitch : MonoBehaviour {
public GameObject gun1;
public GameObject gun2;
public GameObject gadget3;
public GameObject gadget4;
public bool tempReload = false;
//public GameObject gun;
public Weapon weaponScript;
// Use this for initialization
public void Start(){
//weaponScript = gun1.GetComponent<Weapon>();
//tempReload = weaponScript.reloading;;
//tempReload = weaponScript.reloading;
}
// Update is called once per frame
public void Update () {
if(gun1.activeSelf ==true){
weaponScript = gun1.GetComponent<Weapon>();
tempReload = weaponScript.reloading;
}
if(gun2.activeSelf ==true){
weaponScript = gun2.GetComponent<Weapon>();
tempReload = weaponScript.reloading;
}
if(gadget3.activeSelf ==true){
weaponScript = gadget3.GetComponent<Weapon>();
tempReload = weaponScript.reloading;
}
if(gadget4.activeSelf ==true){
weaponScript = gadget3.GetComponent<Weapon>();
tempReload = weaponScript.reloading;
}
if(tempReload == false){
if (Input.GetButtonDown("SwitchWeapons")){
switchWeapons();
}
if(Input.GetButtonDown("Gadget3")){
gun2.gameObject.SetActive(false);
gun1.gameObject.SetActive(false);
gadget3.gameObject.SetActive(true);
gadget4.gameObject.SetActive(false);
}
if(Input.GetButtonDown("Gadget4")){
gun2.gameObject.SetActive(false);
gun1.gameObject.SetActive(false);
gadget3.gameObject.SetActive(false);
gadget4.gameObject.SetActive(true);
}
}
}
public void switchWeapons(){
if(gun1.activeSelf == true){
gun2.gameObject.SetActive(true);
gun1.gameObject.SetActive(false);
gadget3.gameObject.SetActive(false);
gadget4.gameObject.SetActive(false);
//Debug.Log("weapon1 active");
}
else if(gun2.activeSelf == true){
gun1.gameObject.SetActive(true);
gun2.gameObject.SetActive(false);
gadget3.gameObject.SetActive(false);
gadget4.gameObject.SetActive(false);
// Debug.Log("weapon2 active");
}
else {
gun1.gameObject.SetActive(true);
gun2.gameObject.SetActive(false);
gadget3.gameObject.SetActive(false);
gadget4.gameObject.SetActive(false);
}
}
}
and the current weapon select script
using UnityEngine;
using System.Collections;
public class ARSelectScript : MonoBehaviour {
public GameObject ARSelectCanvas;
public GameObject ARHeavyCanvas;
public GameObject ARHeavyAttachmentsCanvas;
public GameObject ArHeavyPrefab;
public GameObject player;
public GameObject arm;
public GameObject HUD;
public Canvas HUDCanvas;
// public GameObject PrimaryWeapon;
public string WeaponSelectScreen;
void Start () {
ARSelectCanvas.SetActive(true);
ARHeavyCanvas.SetActive(false);
ARHeavyAttachmentsCanvas.SetActive(false);
DontDestroyOnLoad(player.gameObject);
DontDestroyOnLoad(HUD.gameObject);
Time.timeScale= 0f;
HUDCanvas = HUD.GetComponent<Canvas>();
HUDCanvas.enabled = false;
}
public void HeavyARMenu(){
ARSelectCanvas.SetActive(false);
ARHeavyCanvas.SetActive(true);
ARHeavyAttachmentsCanvas.SetActive(false);
}
public void ARSelectMenu(){
ARSelectCanvas.SetActive(true);
ARHeavyCanvas.SetActive(false);
ARHeavyAttachmentsCanvas.SetActive(false);
}
public void ARHeavyAttatchmentsMenu(){
ARSelectCanvas.SetActive(false);
ARHeavyCanvas.SetActive(false);
ARHeavyAttachmentsCanvas.SetActive(true);
}
public void BackToWeaponSelectScreen(){
Application.LoadLevel(WeaponSelectScreen);
}
public void SaveArHeavy(){
// ArHeavyPrefab.SetActive(true);
NewWeaponSwitch SwitchScript = arm.GetComponent<NewWeaponSwitch>();
SwitchScript.gun1 = ArHeavyPrefab;
Application.LoadLevel(WeaponSelectScreen);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612034807im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I make this script only apply to the local player 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I change weapons with Photon (FPS) C# 0 Answers
Code Wont Work? 0 Answers