Quantcast
Channel: Questions in topic: "skip"
Viewing all articles
Browse latest Browse all 85

How to fast forward time (or just skip it) properly?

$
0
0
Not sure what is exactly going wrong here. I have a world time that runs on update: if (!worldInteractions.worldIsPaused && !worldInteractions.showMainMenu){ worldTime += Time.deltaTime; } and I use that time to drive the game world clock : function GameTime () { if (worldTime - lastChange > 10) { //Decides how many seconds a game 'minute' lasts. minutes++; if (minutes == 60) { minutes = 0; hour++; if (hour == 12) { if (ampm == "am") { ampm = "pm"; } } if (hour == 13) { hour = 1; } } lastChange = worldTime; } } In my project, when the player is in a dialog, he is able to skip a dialog line and also advance the time it would take to display it(e.g. if a line of text would display for 5 seconds and the player skips it, then it will be 5 seconds later). This is how a dialog is currently displayed (I'm doing a typewriter effect from a script shown in Unity wiki I think): function DoTextLine (){ currentDisplayLine = null; for (var letter in currentScriptStep.textLine.ToCharArray()) { currentDisplayLine += letter; yield WaitForSeconds (letterPause); } yield WaitForSeconds (endDialogPause); currentState = DialogStates.Idle; } And when the player presses a key to fast forward that dialog I do this: function SkipDialogLineAction (){ if (dialogInteractions.currentState == DialogStates.ShowTextLine){ Time.timeScale = 90; } } and once the textLine has been fully displayed in faster speed I go back to the normal timeScale: if(currentState == DialogStates.Idle && Time.timeScale == 90){ Time.timeScale = 1; } I thought this was working all correctly but I noticed that time passes much faster than it should. If I skip a dialog line of 5 secs I end up passing almost 30 secs from the worldTime variable. I'm wondering what I could be doing wrong. I'm not totally comfortable with Time.time and Time.deltaTime and wondering if there is a error there? Or if maybe using yield on the Typewriter effect could be causing the issues with the timeScale difference... Or maybe there is a much better way to achieve this? Any help very appreciated!

Viewing all articles
Browse latest Browse all 85

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>