question

mohamed-sunoob avatar image
mohamed-sunoob asked

How to Show 'buy' button relevant to character selected ?

I have created 20 character in unity 3d, the behavior of Character selection is Carousel. so I have added all my Characters as a Inventory items, I can able to instantiate the 'buy' button in UI. Now problem is i need to instantiate the buy button appropriate to active character, is there any way to solve this?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mohamed-sunoob avatar image
mohamed-sunoob answered

@Citrus Yan Functionality is working, the only problem is need to show the button for relevant active character.

  public void GetItemPricesofPlanes()
    {
        GetCatalogItemsRequest request = new GetCatalogItemsRequest();
        request.CatalogVersion = "ilhaV1";






        PlayFabClientAPI.GetCatalogItems(request, result =>
        {
            List<CatalogItem> items = result.Catalog;
            


            foreach (CatalogItem i in items)
            {
               


                uint cost = i.VirtualCurrencyPrices["GC"];
                foreach (PlayersItems editorItem in Planes)
                {
                    if (editorItem.Name == i.ItemId)
                    {
                        editorItem.Cost = (int)cost;
                    }


                }
                Debug.Log(cost);
            }







       
                    foreach (PlayersItems i in Planes)


                    {   




                        GameObject o = Instantiate(Buy, BuyChoosePanel.transform.position, Quaternion.identity);
                        o.transform.GetChild(0).GetComponent<Text>().text = i.Cost.ToString();


                        o.transform.SetParent(BuyChoosePanel.transform);
                        o.transform.GetComponent<Button>().onClick.AddListener(delegate { MakePurchase(i.Name, i.Cost); });
  


                    }
                
            
            
          
        














        }, error => { Debug.LogError(error.ErrorMessage); });


    }



//Carousel Script to switch Characters



        CharacterList = new GameObject[transform.childCount];


        for (int i = 0; i < transform.childCount; i++)


            
            CharacterList[i] = transform.GetChild(i).gameObject;
          


        foreach (GameObject go in CharacterList)
            go.SetActive(false);


        if (CharacterList[index])


           
            CharacterList[index].SetActive(true);












    }




    public void PrevCharacterNew()
    {
        CharacterList[index].SetActive(false);


        index--;
       
        if (index < 0)
            index = CharacterList.Length - 1;
        
  




        CharacterList[index].SetActive(true);
        
        textName();
    }






    public void NextCharacterNew()
    {
        CharacterList[index].SetActive(false);


        index++;
        if (index == CharacterList.Length)
            index = 0;
        textName();
        


        CharacterList[index].SetActive(true);


    }




    void changeName()
    {
        //for (int i = 0; i < namePlayer.Length; i++)
        //{
        //    Debug.Log(namePlayer[index]);




        //}


    }
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Use a static variable to "point to" the current selected character might help.

0 Likes 0 ·
Michael Brilz avatar image Michael Brilz commented ·

hey maybe you have facebook or something else where you could maybe help me with your solution.

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

Do you mean that you want the button act on the selected character when clicked?

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mohamed-sunoob avatar image mohamed-sunoob commented ·

Yes, Exactly that i want. is there any way ?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan mohamed-sunoob commented ·

You can use a variable that holds the name/id of the selected character, when the "OnClick" event occurs, the result function will try to read that variable and perform subsequent operations. Please refer to the Unity Doc to learn more.

0 Likes 0 ·
mohamed-sunoob avatar image mohamed-sunoob Citrus Yan commented ·

I tried giving different tags to each character, and if tag is equal to item id then do this... but this didn't worked.

0 Likes 0 ·
Show more comments
Show more comments
Michael Brilz avatar image
Michael Brilz answered

I have the same Problem and need help:(

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.