Quantcast
Channel: Questions in topic: "selectiongrid"
Viewing all articles
Browse latest Browse all 94

Weapon Selection Script

$
0
0
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 WeaponNames = new List(); 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 Weapons = new List(); 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); } } } }

Viewing all articles
Browse latest Browse all 94

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>