This site uses cookies! Learn More
- 0
Sign in to follow this
Followers
0

UI button not functioning properly after first use [unity 5.1.1]
Asked by
KrypTik_Sweller
Asked by
KrypTik_Sweller
The UI button is supposed to "decode" an engram similar to in destiny. What it is supposed to do(which it does fully the first time):
-delete the engram from player inventory
-randomly select a weapon from a list of weapons of the same class
-debug.log("decoded") right before menu pops up
-open a menu displaying an image of the decoded weapon
What it does every time after the first time:
-deletes the engram from player inventory
-opens a menu displaying an image of the weapon FROM the first time you decoded an engram
- no debug.log (it only shows once in log while the rest of the script still opens the menu after that line when i press the button again)
here is a code dump of the public void called on when the weapon is decoded:
public void DecodeEngram(string type)
{
//deleting the engram after decode button pressed
if (type == "Scrap")
{
PlayerInv.Engrams[0] -= 1;
}
if (type == "Common")
{
PlayerInv.Engrams[1] -= 1;
}
if (type == "Rare")
{
PlayerInv.Engrams[2] -= 1;
}
if (type == "Mythic")
{
PlayerInv.Engrams[3] -= 1;
}
if (type == "Dark")
{
PlayerInv.Engrams[4] -= 1;
}
Debug.Log("decode");
//debug ^^ and randomly selecting weapon of same class \/\/
WeaponIndex[] allWeapons = FindObjectsOfType<WeaponIndex>();
int totalOfType = 0;
foreach (WeaponIndex cur in allWeapons)
{
if (cur.Rarity == type)
{
totalOfType += 1;
weaponOfType[totalOfType - 1] = cur;
}
}
int chance = Random.Range(0, totalOfType - 1);
SelectedWeapon = weaponOfType[chance];
EngramDecode.SetActive(true); //opens the menu
WeaponIconImage.sprite = SelectedWeapon.WeaponIcon; //sets image in menu to selected weapon icon
}
Share this post
Link to post
Share on other sites