- Home /
Modifying scroll texture
Hi.
How can I modify the scroll script so that it scrolls the texture everytime a button is pressed for one second for example and then stops? The way I tried it only plays it on some frames doesn't play the whole scrolling like it is without the Input.GetKeyDown. Basically, I want to be able to play with it, how much time it will scroll, then stop? Thanks.
// Scroll main texture based on time
var scrollSpeed : float = 0.5;
function Update() {
if(Input.GetKeyDown ("5"))
{
var offset : float = Time.time * scrollSpeed;
renderer.material.mainTextureOffset = Vector2 (offset, 0);
}
}
Answer by aldonaletto · Jul 31, 2011 at 04:10 PM
It can be done with some modification of your original script. I forced the offset value to be modulo 1 in order to avoid a well known bug with huge offsets:
// Scroll main texture based on time var scrollSpeed : float = 0.5; var scrollTime : float = 1; // scroll duration in seconds private var endScroll: float = 0; private var offset: float = 0; // offset now is permanent instead of temporary
function Update() {
if(Input.GetKeyDown ("5"))
{ // set end scrolling time
endScroll = Time.time + scrollTime;
}
if (Time.time < endScroll)
{
offset += Time.deltaTime * scrollSpeed;
// use offset modulo 1 to avoid a known problem with big offsets
renderer.material.mainTextureOffset = Vector2 (offset % 1, 0);
}
}
EDITED: Ok, I got it: the scroll started at random positions because it was based on Time.time. I edited the script to scroll after the last position: the offset variable was moved out of the function to become permanent, not temporary, so it can "remember" the previous position.
Yeah, but still the whole scroll doesn't go it stops at some frame.
I suppose I've got it: the texture was starting at random positions because it was based on Time.time. I edited my answer to make it start at the last position.
Actually the scroll time needs to be set to 2 so that the whole cycle is completed. Anyway, this is what I wanted thank you for all the amaizing work and help you are giving on every post. I just can't figure out why I can't vote up your post. I am most thankful for your kind help. Cheers and all the best.
OH $$anonymous$$Y GOD Aldonaletto you are boss.i had problem of big texture offset.from your answer i got solution.you saved my whole week. thank you very much.
Your answer
Follow this Question
Related Questions
Repositioning remote GUI Texture 1 Answer
GUI Info button not displaying 1 Answer
How can i show the texture in the array? 2 Answers
DrawTexture GUI iPhone 1 Answer
GUI Texture fixed on Object 1 Answer