Search Unity

Gettting a product's definition by script

Discussion in 'Unity IAP' started by Adrien-Ninpo, Jan 28, 2019.

  1. Adrien-Ninpo

    Adrien-Ninpo

    Joined:
    Oct 2, 2018
    Posts:
    17
    I'm trying to make a simple script to display the price of a given product, but I just have no idea on how to access the catalog by script. I was expecting something along the line of `ProductDefinition.GetProductById`, but I can't find anything that ressembles that.

    I also thought I could have my script just read the datas from the nearby IAPButton, but it turns out the button doesn't provide information on the product either.

    I would have gladly used the `titleText`, `descriptionText` and `priceText` from the IAPButton instead of writting my own script, my organization wants us to only use TextMeshPro components, which aren't compatible with mere Text component type.

    Right now the only way I can think of to get any info about a product is to have an IAPButton write these infos into text components, then have my scripts read them back. Surely there must be another way, right ?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Don't you already know the prices of your products? Otherwise, you'll want to use priceText from the button. Are you using Codeless IAP and IAP Buttons?
     
  3. Adrien-Ninpo

    Adrien-Ninpo

    Joined:
    Oct 2, 2018
    Posts:
    17
    Hi, thanks for your reply.

    The point is that if the prices ever change on the stores, we won't need to rebuild the application in order to have the correct price displayed in the shop.

    Our shop is set up using IAPButtons, and the provided IAPListener script. Everything from there is plugged to the UnityEvents from these two scripts.

    The workaround I mentionned about reading datas from the text component do work so far, it just feels like a dirty hack.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Understood! I'm glad the workaround is working for you for now. You are free to modify the IAPButton and Listener scripts, just be advised that updating IAP in the future will likely overwrite your changes.