[Question] Advice on game architecture & scripting

Hi guys, maybe not entirely the correct section, but my question is somewhat related to scripting. I’m a novice developer and scrape & google my knowledge and code together from the various resources and I could use some advice on how to deal with the following scenario:

In the game I’m creating, a player can learn skills from level 1 to level 5. These skills are learned over time (1st level takes 4 minutes, 2nd level takes 15 minutes, etc). What would be the best approach to:

  • Store the skill level (static?)
  • Have learning continue between scene’s (is that even possible?)

Ultimately I would like to move this ‘logic’ to a online back-end in the future to make this multi-playable.

And I also have some specific code question. Right now I use this code for a timer:

public Text timerText;
    public bool isConnected = false;
  
    int count = 5;
  
  
  
    public void StartConnecting() {
        if (!isConnected) {
            StartCoroutine("ConnectingTimer");
        }
        if (isConnected) {
            StartCoroutine("DisconnectingTimer");
        }
    }
  
  
    IEnumerator ConnectingTimer() {
        while (!isConnected) {
            yield return new WaitForSeconds(1.0f);
            count--;
            timerText.text = "Connected in : " + count.ToString();
            if (count <= 0) {
                isConnected = true;
                timerText.text = "DISCONNECT";
            }
        }
        count = 5;

the StartCoroutine is fired from a button. If I click this button several times, the countdown speeds up. How can I prevent that from happening? Make the button onClickable? If yes, how? :slight_smile:

Any advice is appreciated :slight_smile:

public Text timerText;
public bool isConnected = false;
public bool inProgress = false;
int count = 5;

public void StartConnecting()
{
    if(!inProgress)
    {
        if (!isConnected)
        {
            StartCoroutine("ConnectingTimer");
        }
        if (isConnected)
        {
            StartCoroutine("DisconnectingTimer");
        }
    }
}

IEnumerator ConnectingTimer()
{
    inProgress = true;
    while (!isConnected)
    {
        yield return new WaitForSeconds(1.0f);
        count--;
        timerText.text = "Connected in : " + count.ToString();
        if (count <= 0)
        {
            isConnected = true;
            timerText.text = "DISCONNECT";
        }
    }
    count = 5;
    inProgress = false;
}
1 Like

Ah! Add another bool!
Thank you kindly :slight_smile: