Search Unity

in app purchase

Discussion in 'Scripting' started by riccardoleoni, Jun 18, 2019.

  1. riccardoleoni

    riccardoleoni

    Joined:
    May 29, 2019
    Posts:
    9
    Hi guys I need help to create a script. In the game there is a shop, a part managed by IAPs with real money and the other one with game currency. I would like to create a system where the player, if he wants to add more coins, buys them with gems .. example 1000 coins at the cost of 250 gems ... how do you do it?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Too vague of a question really. The forum is best at helping with very specific coding problems. If you need help just getting started, you're probably better off hiring someone.
     
  3. riccardoleoni

    riccardoleoni

    Joined:
    May 29, 2019
    Posts:
    9
    what I want to do is this .... the player buys gold with gems
     
  4. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,735
  5. riccardoleoni

    riccardoleoni

    Joined:
    May 29, 2019
    Posts:
    9
  6. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    Rule-of-thumb: when you have a complex task, break it down into smaller pieces until either you know how to do the piece or you know exactly what you'd need to learn in order to do the piece.

    Assuming that "coins" and "gems" are things that your game already tracks, this can be broken down into:
    1. You need an input mechanism (example: a button) that allows the user to express their intent to perform this transfer
    2. You need to check if the user is allowed to do it (example: they have at least 250 gems)
    3. You need to decrease gems by 250 and increase coins by 1000
    All of those are pretty basic. Obviously, no one is born knowing how to do them, but they're steps I would normally gloss over when talking about a larger problem, because I would assume a poster knows how to do them unless they say otherwise.

    But your post also alludes to real-money purchases. Those are much more complicated than the sequence above, because you have to interact with real-life monetary systems, which have a bunch of complicated rules due to various reasons of security, competing third-party interests, and historical accident. Also, there are a bunch of laws governing them, which means if you're not careful it's possible to write a program that technically "works" but could still get you in big trouble later on (e.g. if you're not taking appropriate security precautions when handling secret data).

    So, for instance, you probably don't want to be writing the code that directly processes credit card numbers.

    You probably want to be using some kind of third-party tool for handling real-money transactions that abstracts the "real" part away and doesn't require your program to directly handle any financial data (and has a contract that indemnifies you if they somehow mishandle the money). How to use that tool would then be beyond the scope of a normal forum post; that's the domain of a tutorial or a technical manual.
     
    Joe-Censored likes this.
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You could use Unity IAP for free, you can enable it on the Services panel in the Unity Editor.