• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheKnight · Jul 31, 2011 at 01:36 PM · javascriptguitexturescroll

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);
 }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheKnight · Jul 31, 2011 at 04:23 PM 0
Share

Yeah, but still the whole scroll doesn't go it stops at some frame.

avatar image aldonaletto · Jul 31, 2011 at 05:17 PM 0
Share

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.

avatar image TheKnight · Jul 31, 2011 at 09:45 PM 0
Share

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.

avatar image shakac · Apr 02, 2014 at 06:04 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges