For this week my goals were to add audio ,add a little more functionality and polish the game
and submit it by the end of the week.
Firstly I started off by using Time.Timescale to 0 and freeze the game by
default but it only freezes or pauses functions that be dependent on the frame
rate then I set up the start button to
play a method on click to set the timescale back to 1.Firstly, a few things to
be noted while using timescale is that 0 freezes everything based on the frame
rate and 1 unfreezes it while using any float between 0 and 1 would slow down
the scale for example if Time.timescale
= 0.5f time will work but it will be 2 times slower than it normally
is . Secondly you should probably know
that everything timescale affects all the time variables of the time class.
After using timescale in the start method I noticed that the
distance counter would start on 0.2f even though it was being called thus I
moved the timescale to void awake to counter this bug in the game. The reason I
used Void awake was that I would only need the method to be called once when
the game was initialized and I would call another method to set the timescale
back to 1 .To understand using timescale and void awake better I would recommend reading unity docs and there is a reference to it in the references section . (Unity, n.d.) (Unity, n.d.) 
The reason I am passing a Boolean pause in the method is because I wanted to check if it is clicked before it would set the time scale back to 1 in addition to passing the method into the button's OnClick .
After working on the instantiation for a while I noticed
that some of the sprites were spawning with a rotation as I had instantiated
them that way so that the coins patterns rotation can be changed while instantiating. The
root cause for this was that I rotated the coin prefab while making coin
patterns but could not change them thus as a quick fix I rotated some sprites
if they had certain tags which was a quick fix for my game.If i were to encounter such a problem again i would definitely not apply a quick fix but take the time to change the rotation prefab and recreate the coin patterns .
lastly i needed to pause the audio while the pause button was pressed but I needed to access the audio component from the script first this was easily accomplished by accessing the audiosource class after which accessing the audio component using GetComponent and muting it using audio.mute = true within a function that muted the audio
If you found this blog helpfull please share , comment and give feedback on it so that i may improve on it .
References
Unity. (n.d.). Unity - Scripting
API:. Retrieved November 10, 2015, from http://docs.unity3d.com/ScriptReference/Time-timeScale.html
Unity. (n.d.). Unity -
Scripting API:. Retrieved from
http://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html


No comments:
Post a Comment