Updating Score [Found a Solution Myself. Will Still Take Suggestions for Cleaner Code]

Hello all, I’ve been taking a stab at this with my primitive knowledge of code for a bit now and come to you at a loss.

What I am trying to accomplish is to have a timer variable (the time the particular session has been in play) and add that to the score and use it as a determinant for other game factors (an increasing difficulty curve).

Right now I have this timer variable calculated in my Update() method using a StartTime variable in my Start() method.

public void Update()

{

timer = Mathf.RoundToInt(Time.time - StartTime);

}

This timer is then added to the score via a separate AddScore method

public void AddScore(int newScoreValue)

{

    score += (newScoreValue+timer);

    UpdateScore();

}

Later on there is an UpdateScore method that later records the score to the screen. And this seems to work, for the most part. My issue is that I can’t seem to get the code to update in real time. Meaning, I want the score to tick up every second by an increment of one if that makes sense. While not ultimately important to my final goal, it is a little jarring for the time update to only happen whenever a different trigger occurs.

Thank you for any help. Pretty new to coding in general and am using Unity (and game making) to play a bit of in my skills. If it helps any, I’m trying to expand upon the tutorial for Space Shooter. My logic was to use the tutorials as a base and experiment further.

Quick Edit: If there is some answer to this type of situation already, feel free to direct me there. I couldn’t find anything concerning this in particular but I’m sure I just missed it.

Are you using Time.deltatime()? It calculates the time between each frame. Using this to remove from a float in an update method would tick every second.

Actually, I solved my own issue messing around with it some more. For any that may be interested, I realized where my derp was. In my UpdateScore() method, I changed the scoreText.text = "Score: " + score.ToString(); line to scoreText.text = "Score: " + (score+timer).ToString();and this solved my issue of the score not updating every second. Thanks @Skyunarankage for the suggestion, anyways. I hope you respond explaining what you wanted me to do so I might be able to tuck that under my belt later.