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 /
  • Help Room /
avatar image
0
Question by andreyazbyn · Sep 14, 2015 at 09:53 AM · c#scenesweapon systemweaponchanging

Weapon Select Menu

i want to make a weapon select screen in another scene (not in the main one beacause i dont want the players to change all weapons in game) here is the script for the weapon select screen(very simplified ) using UnityEngine; using System.Collections;

 public class WeaponSelectScreen : MonoBehaviour {
 
     public string MainMenu;
 
     public GameObject playerGunsCanvas;    //a empty game object as a child of a main canvas where you see the weapons that you chose
     public GameObject weaponTypeSelectCanvas; //a empty game object as a child of a main canvas where you select the weapon type (primary, secondary)
     public GameObject primaryWeaponsCanvas;    //a empty game object as a child of a main canvas where you select the primary weapon type (assault rifle, smg, lmg...)
     public GameObject assaultRiflesCanvas;    //a empty game object as a child of a main canvas where you select the assault rifle (assault rifle 1 ,assault rifle 2...)
     public GameObject assaultRiffle1Canvas;    //a empty game object as a child of a main canvas where you select the assault rifle1 atatchments (atatchment 1 ,atatchment 2...)
     public GameObject assaultRiffle2Canvas;    //a empty game object as a child of a main canvas where you select the assault rifle atatchments (atatchments 1 ,atatchment 2...)
     
 
     public GameObject assaultRiffle1Prefab;    
     public GameObject assaultRiffle2Prefab;
     public GameObject atatchment1Prefab;
     public GameObject atatchment2Prefab;
     public GameObject atatchment3Prefab;
 
     
     public void PrimaryWeaponMenu(){ //when the Primary Weapon button is pressed in the weaponTypeSelectCanvas
         primaryWeaponsCanvas.SetActive(true);
         assaultRiflesCanvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         weaponTypeSelectCanvas.SetActive(false);
         playerGunsCanvas.SetActive(false);
     }
     public void AssaultRifleMenu(){    //when the AssaultRifle button is pressed in the primaryWeaponsCanvas
         primaryWeaponsCanvas.SetActive(false);
         assaultRiflesCanvas.SetActive(true);
         assaultRiffle1Canvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         weaponTypeSelectCanvas.SetActive(false);
         playerGunsCanvas.SetActive(false);
     }
     public void AssaultRifle1Menu(){//when the AssaultRifle1 button is pressed in the assaultRiflesCanvas
         primaryWeaponsCanvas.SetActive(false);
         assaultRiflesCanvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(true);
         assaultRiffle1Canvas.SetActive(false);
         weaponTypeSelectCanvas.SetActive(false);
         playerGunsCanvas.SetActive(false);
     }
     public void AssaultRifle2Menu(){//when the AssaultRifle2 button is pressed in the assaultRifflesCanvas
         primaryWeaponsCanvas.SetActive(false);
         assaultRiflesCanvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(true);
         weaponTypeSelectCanvas.SetActive(false);
     }
     public void ChangeLoadout(){//when the Change Loadout button is pressed in the playerGunsCanvas
         primaryWeaponsCanvas.SetActive(false);
         assaultRiflesCanvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         weaponTypeSelectCanvas.SetActive(true);
         playerGunsCanvas.SetActive(false);
 
     }
     public void SaveMenu(){//when the Accept button is pressed in the assaultRiffle1Canvas or assaultRiffle1Canvas
         primaryWeaponsCanvas.SetActive(false);
         assaultRiflesCanvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         assaultRiffle1Canvas.SetActive(false);
         weaponTypeSelectCanvas.SetActive(false);
         playerGunsCanvas.SetActive(true);
         
     }
 
     public void BackToMainMenu(){//when the Cancel button is pressed in any menu
         Application.LoadLevel(MainMenu);
     }
 
 
 }
 

and this is the weapon switch script using UnityEngine; using System.Collections;

 public class NewWeaponSwitch : MonoBehaviour {
 
     public GameObject gun1;
     public GameObject gun2;
     public GameObject gun3;
     public GameObject gun4;
     // Use this for initialization
     public void Start () {
 //    gun1 = GameObject.FindGameObjectWithTag("")
 //    gun1 = GameObject.FindGameObjectWithTag("")
     }
     
     // Update is called once per frame
 public    void Update () {
         if (Input.GetButtonDown("SwitchWeapons")){
             switchWeapons();
         }
     }
     public    void switchWeapons(){
         if(gun1.activeSelf == true){
             gun2.gameObject.SetActive(true);
             gun1.gameObject.SetActive(false);
             //Debug.Log("weapon1 active");
         }
         else if(gun2.activeSelf == true){
             gun3.gameObject.SetActive(true);
             gun2.gameObject.SetActive(false);
         //    Debug.Log("weapon2 active");
         }
         else if(gun3.activeSelf == true){
             gun4.gameObject.SetActive(true);
             gun3.gameObject.SetActive(false);
             //    Debug.Log("weapon2 active");
         }
         else if(gun4.activeSelf == true){
             gun1.gameObject.SetActive(true);
             gun4.gameObject.SetActive(false);
             //    Debug.Log("weapon2 active");
         }
     }
 }
 

how can i make it so when you press the accept button the weapon gets set as gun1 in the level?

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

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Storing diffrent bullet amounts for different Weapons. 1 Answer

Changing player position when changing scene 1 Answer

How to make ui only activate once 1 Answer

Prefab destroyed upon instantiation 0 Answers

Having a few script errors that I ran into. 1 Answer


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