- Home /
Problem with time on scrolling texture
Hi. I've got a script:
var scrollSpeed = 0.25;
function FixedUpdate()
{
var offset = Time.time * scrollSpeed;
renderer.material.mainTextureOffset = Vector2(0,offset);
}
The problem is that I have the script on an object that is instantiated while playing, so the offset is bigger if you create the object later in the game.
I'm sure I missed something but I don't know how to fix it. Please help.
Answer by robertbu · Mar 18, 2013 at 06:00 AM
Create your own timer or you can subtract the start time:
var scrollSpeed = 0.25;
private var startTime = 0.0;
function Start() {
startTime = Time.time;
}
function FixedUpdate() {
var offset = (Time.time - startTime) * scrollSpeed;
renderer.material.mainTextureOffset = Vector2(0,offset);
}
thanks! But when I try it on the tiling of a texture it doesn't work. It only sets the tiling to that number...
var tiling = (Time.time - startTime) * tileSpeed;
renderer.material.mainTextureScale = Vector2(0,tileSpeed);
Can you help?
I might be able to help if I can better understand the problem. This code above will start the texture at the beginning (offset 0) at the time the object is created. What exactly are you seeing and what problem are you trying to fix.
I need the tiling of the texture to get bigger every second, but with the same speed on every object or computer
Doctor Jellyface, did you mean to put Vector2(0, tileSpeed) above? Shouldn't it be Vector2(0, tiling)?
You changed questions on me. The original question was about offset, now you are asking about scale. The issues is that you are putting in '0' for an X scale. Use this ins$$anonymous$$d:
renderer.material.mainTextureScale = Vector2(1,tileSpeed);
...or whatever value you want for x.