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 Sinichka · Feb 11, 2014 at 01:51 PM · textureoffset

Offset texture on an object

Hi! On https://constrvct.com/designs/new has an interesting feature: when you move the mouse texture in the central large square is shifted textures on 3D objects. How is it possible to implement in Unity? Does anyone have a ready script?

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
0

Answer by robertbu · Feb 11, 2014 at 04:50 PM

This can be done using Material.SetTextureOffset(). Below is a example script. Create and object and a Quad. Put the same material on both. Attach this script to the Quad. Drag and drop the other object to the 'object' variable in the script attached to the quad.

 #pragma strict
 
 var object : GameObject;
 var factor = 0.01;
 
 private var startPos : Vector2;
 private var startOffset : Vector2;
 
 function Start() {
                     // Could be done in the editor
     renderer.material.SetTextureScale("_MainTex", Vector2(0.2, 0.2)); 
 }
 
 function OnMouseDown() {
     startPos = Input.mousePosition;
     startOffset = renderer.material.GetTextureOffset("_MainTex");
 }
 
 function OnMouseDrag() {
     var v = (Input.mousePosition - startPos) * factor;
     renderer.material.SetTextureOffset("_MainTex", startOffset - v);
     object.renderer.material.SetTextureOffset("_MainTex", startOffset - v);
 }

There is one problem with this code I did add the code to solve. This code uses mouse coordinates to calculate the amount of movement of the texture offset, so it is not platform independent. You'll need additional work if you are targeting multiple platforms.

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 Sinichka · Feb 11, 2014 at 07:35 PM 0
Share

thank you!

What is Quad?

avatar image robertbu · Feb 11, 2014 at 07:40 PM 0
Share

In the editor do:

 Game Object > Create Other > Quad

A Quad is a vertical plane composed of only two triangles, has a world size of 1 x 1, and the backside of the plane is the surface. So in a new scene, if you create a Quad at the origin, the material placed on the Quad will be visible to the camera. Quads were introduced around Unity 4.1. If you are using an earlier version of Unity, then you can use the CreatePlane editor script from the Wiki to produce the same kind of object.

avatar image Sinichka · Feb 11, 2014 at 08:08 PM 0
Share

thank you so 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.

Follow this Question

Answers Answers and Comments

18 People are following this question.

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

Related Questions

Interactive Textures? 1 Answer

How to add render able Texture in Unity 3d for iOS 0 Answers

Infintely scrolling texture ends?(only scrolls through once) 1 Answer

How can I create a UV move tool? 0 Answers

Animation Tiling/Offset 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