public override void SpawMenu(KeyCode menuKeyCode) { var weapons = _inventory.GetWeapons(); if (_inventory == null || weapons == null) { return; } MenuAction[] buttons = new MenuAction[weapons.Length]; for (var i = 0; i < weapons.Length; i++) { var weapon = weapons[i]; var weaponSetter = weapon.GetComponent <WeaponSetter>(); if (weapon != null) { buttons[i] = new MenuAction { ButtonAction = () => _weaponHolster.Equip(weapon), Title = weaponSetter.Weapon.name, Sprite = weaponSetter.Weapon.Avatar, Color = Color.white }; } } var menu = Instantiate(MenuPrefab) as Menu; menu.Initialize(menuKeyCode, transform, buttons); }
/// <summary> /// Handles pickup /// </summary> public void Pickup() { var colliders = new Collider2D[10]; var collitionCount = _collider.GetContacts(colliders); for (int i = 0; i < collitionCount; i++) { var collider = colliders[i]; var go = collider.gameObject; //This is the game object you collided with if (go == gameObject) { continue; //Skip the object itself } if (go.GetComponent <ItemBase>() == null) { return; } if (_inventory.AddItem(go)) { var renderer = go.GetComponent <Renderer>(); if (renderer != null) { renderer.enabled = false; } var weapon = go.GetComponent <WeaponSetter>(); if (weapon != null) { _weaponHolster.Equip(go); } } } }