Wednesday, 26 November 2014

TimerScript

My job on this task mainly was to do the coding. I have not really coded before so this was all a very new learning experience for me and I have learnt a lot over the course of this.

This timerScript was something I haven't tried before and I learnt about GUI text functions. This script links together with the other scripts and I really learnt how useful 'if' statements are and how they can be used to their full potential. Not shown here I also found out that you can change the colour of a GUI Label by writing ' GUI.color = Color.green; ' in the OnGUI function. By Putting the restSeconds into an 'if' statement with gameOver = false it stops the timer when you reach the trigger zone which was an issue I was having for a while. The timer used to just be in seconds but I found that by putting in the String.Format it allowed me to choose the setting for minutes and seconds and it made for a much neater looking and intuitive timer. 



All the private variables make for a neater looking inspector and allow for me to assign lines of code to them without errors. The one important public variable that's needed is the timeRemaining as it means it can be adjusted in the inspector which is easier than going into the code every time to change the value of the timer. Here I downloaded a custom font so I was able to adjust the size of the font and make it much more readable for the player to see. I think white is the best colour for it as we have quite a dark game and it shows up well in pretty much all of the lighting. I learnt a lot about GUI Texts during this and how to adjust the text so it's much easier to edit and customise, rather than putting all of the information into the script. 






No comments:

Post a Comment