Search Unity

Creating an Economy System

Discussion in 'Getting Started' started by DivinityStudios, Oct 1, 2015.

  1. DivinityStudios

    DivinityStudios

    Joined:
    Jul 7, 2012
    Posts:
    5
    So like the title says, I am creating an in game economy system and only really have a minor knowledge of javascript. This system isn't going to be anything too complex, but I wanted to set myself this task to gain a better understanding of how they work and how I can implement them into my games projects.

    With this system I want to do the following :
    • Gain money when I press a button
    • Open an interface that I can navigate with either a mouse or a controller
    • Buy items and have them subtract from my money variable
    • Be unable to buy items I cannot afford
    I am going to be spending the next week or so researching how to do this, and then trying to do it for another week, as part of a university experiment to see which engine (unity or unreal) is better equipped for creating systems such as this, to aid in choosing an engine for a games project.

    So this post is just me generally asking if there are any certain tutorials I should be looking at, or any good way of setting this up, for example I guess the player controller / character will have the money variable, and the shop will handle the items prices ect ect.

    Thank you all in advance and sorry if this is a lengthy post!
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    In the most basic sense, you don't need any sort of system per se.
    Code (CSharp):
    1. float myCash = 10.5f;    // $10.50
    2.  
    3. // Do this on button click
    4. void GivePlayerMoney(float amount) {
    5.     myCash += amount;
    6. }
    7.  
    8. // Do this when buying an item
    9. void BuyItem(YourItemType item, float cost) {
    10.     if (myCash >= cost) {
    11.         myCash -= cost;
    12.         GivePlayerItem(item);
    13.     } else {
    14.         DisplayMessageToUser("Sorry, you can't afford this");
    15.     }
    16. }
    Obviously with things like GivePlayerItem, DisplayMessageToUser, and YourItemType being things you've defined elsewhere.

    For the interface to handle all of this, I highly recommend looking into Unity's built-in UI system. That said, this is all pretty basic stuff, and any game engine would be equally capable of handling it.
     
    DivinityStudios, Kiwasi and JoeStrout like this.
  3. DivinityStudios

    DivinityStudios

    Joined:
    Jul 7, 2012
    Posts:
    5
    Sorry for such a long reply! But this was really helpful! I guess I'll keep this post updated if I have any questions? Or would it be better to post on the Unity Answers forum instead now? Again thank you for your help! :p
     
  4. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Absolutely post back here! Unity Answers is more for direct answers to technical questions, while the forums are a place for discussion and evolving content.
     
    DivinityStudios likes this.