0
Answered

Picking up coins.

Pandar 4 months ago in Game Creator updated by Marti (Lead Developer) 4 months ago 1

Hey. I want to make a simple 3D walker. The character collects coins (their number should be visible in the UI and in the in-game shop), then: Esс - Main Menu - Shop - and buy something. How difficult is it to organize such a structure, taking into account the preservation of data during the transition to the next level? Coins should be Global Variables? How to organize text in UI and in the shop panel? Need additional modules, like inventory?

Unity version:
Game Creator version:

Answer

+1
Answer
Answered

Hi Pandar; The Inventory module would be ideal in this case. Specially if you plan to have multiple purchasable items. The Inventory would greatly simplify this. However, let me give you a brief explanation about how to do this without the Inventory module.

Coins, as you said, should be made as a Numeric Global Variable, marked as "savable". To pick up coins you'd need to first need to create a game object (let's say a sphere with the isTrigger option enabled) and add a Trigger "On Player Enter". This Trigger will be executed when the Player touches it. The Actions sequence when picking a coin could be:

  1. Add Variable +5 to "Coins" Global Variable
  2. Play a nice sound effect & some particles
  3. Destroy the game object

In order to reuse this coin, you can create a prefab out of this and create multiple instances across your scenes. This will allow you to modify the prefab and affect all coins in your levels without having to modify them one by one.

Great! Now we have the picking mechanic. To display the amount of coins on a UI panel, all you need to do is use the Text Variable component that comes with Game Creator. This looks exactly the same as the Unity Text component, but allows you to select a variable (Global Variable "Coins" in your case) and display its value on screen. The value will be automatically updated when it changes, so you don't need to worry about anything.

As for purchasing power-ups in a store, this is a bit trickier. You'll need to use a Button to detect when the user clicks on a particular power-up from the store and launch a Conditions object, which checks if the variable "Coins" is greater or equal to the price of the power-up. If so, you can enable the power-up (through a boolean variable, for example). Otherwise, you can play an "error" sound effect and print a message that says: You don't have enough coins.

With the Inventory module, however, this last section is really easy. You just need to define the item, its price and create a Merchant object, which allows you to define which objects are on sale though a pre-made UI, with discounts, reselling prices, etc...

I'd suggest you try the approach without the Inventory if you don't have it. If it's enough, great! If not, switching to the Inventory shouldn't be much of a hassle.


Cheers!

GOOD, I'M SATISFIED
Satisfaction mark by Pandar 4 months ago
+1
Answer
Answered

Hi Pandar; The Inventory module would be ideal in this case. Specially if you plan to have multiple purchasable items. The Inventory would greatly simplify this. However, let me give you a brief explanation about how to do this without the Inventory module.

Coins, as you said, should be made as a Numeric Global Variable, marked as "savable". To pick up coins you'd need to first need to create a game object (let's say a sphere with the isTrigger option enabled) and add a Trigger "On Player Enter". This Trigger will be executed when the Player touches it. The Actions sequence when picking a coin could be:

  1. Add Variable +5 to "Coins" Global Variable
  2. Play a nice sound effect & some particles
  3. Destroy the game object

In order to reuse this coin, you can create a prefab out of this and create multiple instances across your scenes. This will allow you to modify the prefab and affect all coins in your levels without having to modify them one by one.

Great! Now we have the picking mechanic. To display the amount of coins on a UI panel, all you need to do is use the Text Variable component that comes with Game Creator. This looks exactly the same as the Unity Text component, but allows you to select a variable (Global Variable "Coins" in your case) and display its value on screen. The value will be automatically updated when it changes, so you don't need to worry about anything.

As for purchasing power-ups in a store, this is a bit trickier. You'll need to use a Button to detect when the user clicks on a particular power-up from the store and launch a Conditions object, which checks if the variable "Coins" is greater or equal to the price of the power-up. If so, you can enable the power-up (through a boolean variable, for example). Otherwise, you can play an "error" sound effect and print a message that says: You don't have enough coins.

With the Inventory module, however, this last section is really easy. You just need to define the item, its price and create a Merchant object, which allows you to define which objects are on sale though a pre-made UI, with discounts, reselling prices, etc...

I'd suggest you try the approach without the Inventory if you don't have it. If it's enough, great! If not, switching to the Inventory shouldn't be much of a hassle.


Cheers!