Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges