Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
KrypTik_Sweller

UI button not functioning properly after first use [unity 5.1.1]

Question

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

1 answer to this question

Recommended Posts

  • 0

Is this a UI related question or a function related question? 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×