Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 pepperedereppep · Nov 02, 2010 at 11:50 PM · animationtextureoffset

texture offset question

sorry for another beginner question. I'm testing this texture offset code on a plane:

var scrollSpeed:float;  //set to .3
function Update () {
if(Input.GetKey("d")){  
    renderer.material.SetTextureOffset("_MainTex", new Vector2(Time.time*scrollSpeed, 0));
    }
}

the scrolling works fine, but everytime I let go of the d key and press it again, i get a jump, like a quick offset.. I'm thinking it probably has something to do with the time code.. any ideas?

Thanks

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

2 Replies

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

Answer by Eric5h5 · Nov 03, 2010 at 12:07 AM

Instead of using Time.time, use your own timer variable, and have it increase when the key is down. The jump is because Time.time continues increasing whether you're holding the key or not.

Comment
Add comment · 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
0
Best Answer

Answer by Adam Rademacher · Nov 03, 2010 at 12:08 AM

Time.time moves regardless of whether the D key is down or not...it's just the time that has passed. So it will 'catch up' if you let go of the key and press it again.

I think what you want to do is something like this:

var scrollspeed : float = 0.3; private var offset : float = 0.0;

function Update() { if(Input.GetKey("d")) { offset += Time.deltaTime; renderer.material.SetTextureOffset("_MainTex", new Vector2(offset, 0)); }

}

This code does essentially the same thing except that the offset will only add time if you have the key down.

Comment
Add comment · Show 1 · 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 pepperedereppep · Nov 03, 2010 at 12:26 AM 0
Share

Thanks everyone. Well, that makes sense lol, I used Time.time because I was looking at the textureoffset docs and they used it there, but I implemented it the wrong way.. Your code works perfectly, thanks!

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Animation Tiling/Offset 0 Answers

What is wrong with my shader? 1 Answer

To Make Animated Textures, how do I create a Tiled Image? 1 Answer

3D Mesh Deformer in Unity3D 2 Answers

Animate Toon Water on Plane? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges