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 Kaze_Senshi · Jul 31, 2012 at 01:27 AM · materialtexture2doffsetfadein

Applying offset to a texture via script

Hello guys, I tried to search something about this but I only found how to apply an offset in a Material, but I want to apply it in one Texture2D that I am using in a fade-in of a level. Can someone help me, thanks.

Comment
Add comment · Show 2
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 ScroodgeM · Jul 31, 2012 at 07:17 AM 0
Share

what do you mean by 'apply it in one Texture2D'? may be you need just edit this texture in iage edit software? or explain a little more what do you want to achieve

avatar image Kaze_Senshi · Aug 01, 2012 at 02:11 AM 0
Share

Well I have one texture that I use in the fadein of a level. But I don't want that it looks the same thing everytime, so I thought to move the offset of the texture, so every time that you go to the level, it'll be different. It is like the effect that you apply when you are doing a parallax effect.

1 Reply

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

Answer by Tommynator · Jul 31, 2012 at 03:28 AM

There are two ways to render Texture2Ds in Unity:

1) If you want to render a texture on the surface of a mesh you have no choice but to assign it to a material and tweak the tiling and offset values.

2) If you use it within the GUI system you can do the same by calling:

 Rect position = new Rect(0, 0, width, height);
 Rect texCoords = new Rect(offsetX, offsetY, 1, 1);
 bool alpha = true;
 GUI.DrawTextureWithTexCoords(position, texture, texCoords, alpha);

In both cases, make sure to set the wrap mode in the Texture2D import settings to 'Repeat' and not 'Clamp'.

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 Kaze_Senshi · Aug 01, 2012 at 02:10 AM 0
Share

Oh $$anonymous$$ thanks for the answer, but here I can't do this code works correctly and the function's documentation is horrible, can you help me, I can only stretch the texture but can't apply the offset, my code is:

fadeoutTexOffset = new Rect( Random.Range( -Screen.width, Screen.width ), Random.Range( -Screen.height, Screen.height ) , 1,1 ); GUI.DrawTextureWithTexCoords( Rect(0, 0,Screen.width, Screen.height), fadeOutTexture, fadeoutTexOffset, true );

avatar image Tommynator · Aug 01, 2012 at 03:08 AM 2
Share

The offset needs to be given in uv coordinates, which is defined in the interval [0,1]. If you apply a full integer offset you will never see any difference :) I don't quite understand what kind of image effect you want to achieve with these random numbers but try Random.Range(0f,1f) ins$$anonymous$$d.

avatar image Kaze_Senshi · Aug 01, 2012 at 03:43 AM 0
Share

Oh that worked, thank you. What I am wanting to do is something like I did in this video http://www.youtube.com/watch?v=1iVXvVFup9E&list=UUa1H$$anonymous$$-eRnglbWUaiOnSz4sA∈dex=0&feature=plcp at the background. The background are planes and I apply some offset at its materials to give the parallax background effect. For future references the line that I changed is:

fadeoutTexOffset = new Rect( Random.Range( 0f, 1f ), Random.Range( 0f, 1f ) , 1,1 );

avatar image Tommynator · Aug 01, 2012 at 06:36 AM 1
Share

Ah I see, but be aware of the fact that the GUI is always rendered ABOVE all 3D content. If you want to have this parallax background effect behind 3D content you should probably just use a simple background plane, tweak the material offset and render it with a second orthogonal camera in a higher depth.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Offset detail texture in c# 1 Answer

Texture / Material offset doesn't work 1 Answer

Is there a way to tell if a Material is visible? 1 Answer

Add material component to object script-wise 4 Answers

Problem with textures ? 1 Answer


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