-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.cs
35 lines (29 loc) · 1.04 KB
/
Inventory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Linq;
using UnityEngine;
using Random = UnityEngine.Random;
public sealed class Inventory : MonoBehaviour
{
[SerializeField] private GameObject[] weaponPartButtons;
[SerializeField] private bool[] activeWeaponPartButtons;
private void Awake() => activeWeaponPartButtons = new bool[weaponPartButtons.Length];
public void ActivatePart(int targetPart)
{
if(CheckAllButtonsActive()) return;
if (activeWeaponPartButtons[targetPart])
{
int randomNumber;
do
{
randomNumber = Random.Range(0, weaponPartButtons.Length);
} while (activeWeaponPartButtons[randomNumber]);
activeWeaponPartButtons[randomNumber] = true;
weaponPartButtons[randomNumber].SetActive(true);
}
else
{
activeWeaponPartButtons[targetPart] = true;
weaponPartButtons[targetPart].SetActive(true);
}
}
private bool CheckAllButtonsActive() => activeWeaponPartButtons.All(t => t);
}