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?
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.
what I want to do is this … the player buys gold with gems
What you want can easily be achieved with this asset. I’ve used it myself and it’s very good. Simple IAP System 1 | Services | Unity Asset Store
thx
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:
- You need an input mechanism (example: a button) that allows the user to express their intent to perform this transfer
- You need to check if the user is allowed to do it (example: they have at least 250 gems)
- 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.
You could use Unity IAP for free, you can enable it on the Services panel in the Unity Editor.