0
\$\begingroup\$

In my game, I'm using the standard SetTextureOffset method to smoothly scroll texture on background quad.

However, on game over, instead of reloading the scene, I'm just reseting all values initial position to give illusion that scene was reloaded. With this approash, i'm unable to use Time.time or Time.timeSinceLevelLoad because, the level was not reloaded and this value stays high. So scrolling is too fast right in the beginning.

Are there any time independent methods to smoothly scroll texture? Thanks.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I would be more inclined to use Mathf.Repeat to alter the texture offset based on the Time.time... This would eliminate the bug you are experiencing... You can limit the repeat method to return a value between 0 and 1. \$\endgroup\$
    – Savlon
    Aug 6, 2015 at 12:55
  • \$\begingroup\$ Tried it. Scrolling is not smooth. The only smooth scrolling I'm getting is when I use one of the time functions. \$\endgroup\$
    – SanSolo
    Aug 6, 2015 at 13:20
  • \$\begingroup\$ I am telling you to use a time function... But the value you should input into the offset should be the value returned by the repeat method. \$\endgroup\$
    – Savlon
    Aug 6, 2015 at 13:42

3 Answers 3

1
\$\begingroup\$
Time.time - timeSinceReset

and when you "reset" you set it to timeSinceReset = Time.time;

\$\endgroup\$
1
  • \$\begingroup\$ It should work, but the scrolling is not smooth, visibly jerky. \$\endgroup\$
    – SanSolo
    Aug 6, 2015 at 12:46
0
\$\begingroup\$

After a bit of tinkering, I found Time.time,Time.timeSinceLevelLoaded were the ones working fine. They had the property of increasing linearly. So I used a float variable "damp" which is incremented by a small value e.g damp+=0.1f; Now it works smoothly.

\$\endgroup\$
0
\$\begingroup\$

You can use CoRoutines instead of Time.time

void IEnumerators( float x )
{
    //x is your time delay. in your code, x=Time.time-lastScrolledTime
    yield return new WaitForSecond(x);
    //scroll texture here
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .