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
1
Question by ronronmx · Jan 31, 2011 at 04:36 AM · guitextureitweensliding

How to slide UVs of a GUI Texture

I have a GUI Texture of a boost gauge, the texture contains all 5 states of the boost gauge. Instead of having to cut them up into 5 different textures and swapping them between them when my condition becomes true, I would rather use only 1 texture and "slide" the UVs down to the new boost gauge state.

I tried GUI.DrawTexture but it doesn't work for sliding UVs. I was thinking about using iTween to slide the UVs, but I don't even know how to specify the UV coordinates between which to slide. Does anyone have a good method for sliding UVs on a GUI Texture ?

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

4 Replies

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

Answer by Eric5h5 · Jan 31, 2011 at 05:14 AM

GUITextures have no access to UVs. You can use a custom plane with an unlit shader, and change renderer.material.mainTextureOffset.

Comment
Add comment · Show 3 · 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 ronronmx · Jan 31, 2011 at 05:16 AM 0
Share

Ah I was beginning to think that, thanks a lot for your quick answer, it saved me lots of "research" time!!!

avatar image ina · Aug 21, 2011 at 12:00 PM 0
Share

hmmm it looks like using the begingroup trick below you don't actually need UV's to animate a sprite on GUI

avatar image flamy · Feb 07, 2012 at 10:56 AM 0
Share

What about Graphics.DrawTexture() funciton ??

avatar image
1
Best Answer

Answer by 3DMagicVR · Mar 19, 2011 at 06:07 AM

Hi, you can make that using this:

Function OnGUI() {
    GUI.BeginGroup(the position and size of the button);
    GUI.Label(the main texture);
    GUI.EndGroup();
}

then use a functiont to make the image moves an "x" value in the position.x example: the image have a 60 width and have 5 images on it, the width of every image will be 12, so add 12 at every x-time in the position.x in the GUI.Label position so the image looks like a gif animation.

Comment
Add comment · Show 3 · 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 ronronmx · Mar 23, 2011 at 03:57 PM 0
Share

Cool trick! I'll definitively try it out, thanks.

avatar image ina · Aug 22, 2011 at 03:00 AM 0
Share

for some reason, gui.label or begingroup forces a stretch or distortion or nonlinear offset error for the sprite frames...

avatar image ina · Aug 22, 2011 at 03:05 AM 0
Share

ahh... six hours of trying to find the fudge factor... it looks like it's due to the 3px/4px margin/padding in default gui style!! setting the label margin padding to 0 fixed it!!

avatar image
2

Answer by maxime.du · Feb 07, 2012 at 11:24 AM

The public beta (Unity 3.5 version) now contains

GUI.DrawTextureWithTexCoords(PositionRect, Texture, UVRect);

This works fine with GUI with GUILayout!

Thanks!

Roger

Comment
Add comment · Show 3 · 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 flamy · Feb 07, 2012 at 11:30 AM 0
Share

the same thing is available earlier too with graphics.drawtexture ()

not a big difference

avatar image maxime.du · Feb 08, 2012 at 09:05 PM 0
Share

But Graphics.DrawTexture() has issues if used within GUILayout. It wont work correctly used in ScrollView() and other elements.

The 3.5 version of DrawTextureWithTexCoords() works perfectly.

avatar image flamy · Feb 09, 2012 at 05:06 AM 0
Share

oh goood to know thanks :)

avatar image
1

Answer by maxime.du · Feb 07, 2012 at 10:27 AM

Graphics.DrawTexture(PositionRect, Texture, UVRect, 0, 0, 0, 0);

solves the problem with one line of code. This does not include GUILayout, here it will work only with some limitations.

Regards, Roger

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a GUI Texture clickable when it's a gameobject animted through iTween? 2 Answers

iTween on GuiTexture 1 Answer

Scale a GUITexture from its center 1 Answer

how to move or fade GUITextures with iTween 2 Answers

iTween RotateTo ... works on GuiTexture? 2 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