Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Borzi · Aug 02, 2013 at 05:55 PM · guimultiplayerfpsweaponselectiongrid

Weapon Selection Script

Hey, I need help with a feature I want to add to my game. I am trying to create a script that allows the player to choose the Weapon that he wants to spawn with. I have created two scripts that are supposed to do this and it works, but when it comes to selecting what weapon I want to use, the second grid on the selection grid cannot be selected for some reason. I have assigned all the weapons and I think it should work. If someone could help, it would be much appreciated! Thank you in advance.

This is the script that is used for the GUI that are supposed to pop up (Note: an external line of Code tells the script when to display the GUI but it works so I did not put it here)

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 
 public class GUIManager : MonoBehaviour 
 {
     public List<string> WeaponNames = new List<string>();
     public int CurWeapon;
     public static GUIManager Instance;
     
     // Use this for initialization
     void Start () 
     {
     Instance = this;
     }
     
     // Update is called once per frame
     void Update () 
     {
     
     }
     
     void OnGUI ()
     {
     if(NetworkManager.Instance.MatchStarted && !NetworkManager.Instance.MyPlayer.IsAlive)
         {
         GUILayout.SelectionGrid(CurWeapon, WeaponNames.ToArray(), 4);
         }
     }
 }


The script that manages the Weapons and switches them

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

 public class WeaponsManager : MonoBehaviour 
 {
 public List<Gun> Weapons = new List<Gun>();
 public static WeaponsManager Instance;
 public int CurWeapon;
 // Use this for initialization
 void Start () 
 {
 Instance = this;
 }
 
 // Update is called once per frame
 void Update () 
 {
 
 }
 
 public void Spawn ()
 {
 CurWeapon = GUIManager.Instance.CurWeapon;
 ApplyWeapon ();
 }
 
 public static Gun FindWeapons (string Name)
 {
 foreach (Gun gu in Instance.Weapons)
         {
         if(Name == gu.Name)
             return gu;
         }
         return null;
 }
 
 public void ApplyWeapon ()
 {
 foreach (Gun gu in Weapons)
         {
         if(gu == Weapons[CurWeapon])
             {
             gu.gameObject.SetActive(true);
             }
         else
             {
             gu.gameObject.SetActive(false);
             }
         }
 }
 

}

Comment
Add comment · Show 1
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
avatar image tw1st3d · Aug 02, 2013 at 06:25 PM 1
Share

throw some Debug.Log()'s that tell you what's doing on in each of your methods, that should help you debug and solve your problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jamora · Aug 02, 2013 at 06:49 PM

SelectionGrid returns an int of the current selection which you need to store if you want to be able to change the selection.

You'll need

 CurWeapon = GUILayout.SelectionGrid(CurWeapon, WeaponNames.ToArray(), 4);
Comment
Add comment · Show 1 · Share
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
avatar image Borzi · Aug 02, 2013 at 07:59 PM 0
Share

Yup that was it thanks

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

16 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

Related Questions

Can anyone give an easy C# code to create a list of rooms in a multiplayer with Photon/PUN 0 Answers

fps multiplayer camera set (posible script) 1 Answer

change weapon only one player in network 0 Answers

non-authorative fps, client controlled character 0 Answers

FPS - Gun Delay while Rotating 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