Search Unity

Mobile game: how to make things happen over "real life" time?

Discussion in 'Android' started by RoxaneNoel, Jun 8, 2021.

  1. RoxaneNoel

    RoxaneNoel

    Joined:
    Oct 5, 2020
    Posts:
    3
    Hi everyone!

    I am very much a beginner at game development and I am currently working on a practice project for a mobile game. The functionality I am trying to achieve is this: in the game, there will be plants which will grow over time (whether the app is open/actively being used *or not*). I know of various ways I could implement this functionality while the game is open and running (like setting up timers or coroutines), but I cannot find anything on how to use "real-world time" in my game. I am at the stage where I am planning how to architect my game code, and this is the issue I am stuck with at the moment (everything else is fine for the time being). Do you have any resources which explain ways to achieve this? I guess I can always use system time or something like that but I don't know how that would play out in more concrete terms.

    Notes:
    - I am not concerned about "cheating", the game is mostly for my portfolio and for practice purposes so there is no concern about, say, leaderboards or monetization. So I can use pretty much any kind of persistent data even if it is not the most "secure".
    - Related for the first point, I am not at a point where using a server or something like that is an option, so please do not recommend suggestions which require a server or some more elaborate means; I am a hobbyist and not a full-on studio!

    Thank you so much in advance :)
     
  2. Clavus

    Clavus

    Joined:
    Jun 6, 2014
    Posts:
    62
    To get the current real world time, you can use DateTime.Now in script. You could store the start time of your plant growth process in the Unity PlayerPrefs database, and then fetch and compare it to the current time to get the real world time span.
     
    LARP likes this.
  3. RoxaneNoel

    RoxaneNoel

    Joined:
    Oct 5, 2020
    Posts:
    3
    Thank you, that makes sense!