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 BuzzKillingtonIII · Jan 17, 2014 at 03:37 PM · 2dmaterialbackgroundc# tutorial

Why does the material not move with the object?

I am making a 2d game and to make movement visible to the user when there are no other objects on the screen the background needs to scroll. Currently I have an object comprising of a quad and a mesh renderer attached as a child to my camera object.

Using the code below the background follows the camera (because it is a child) and the texture scrolls in the correct direction at the correct speed. However the material that is offset does not follow the camera, leaving me with black space (with some weird streaks) once I move out of the original background area.

 void Update () {
     offset = (cameraLocation.transform.localPosition*scrollSpeed);
     //renderer.material.SetTextureOffset("_MainTex", offset);//This has the same effect
     renderer.material.mainTextureOffset = offset;
 }

I cannot find any solutions in the documentation for SetTextureOffset etc and I cant find anyone else with this issue. Any help would be most appreciated.

Comment
Add comment · Show 1
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 robertbu · Jan 17, 2014 at 04:48 PM 0
Share

Select the texture you are using for your background and verify that 'Wrap $$anonymous$$ode' is set to 'Repeat'.

1 Reply

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

Answer by BuzzKillingtonIII · Jan 17, 2014 at 05:11 PM

Thank you robertbu.

By setting the wrap mode to repeat this problem can be avoided. I wont need to change it so it can be done in Start(), although it could be called anywhere.

 void Start () {
      renderer.material.mainTexture.wrapMode = TextureWrapMode.Repeat;
 }
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 robertbu · Jan 17, 2014 at 05:12 PM 0
Share

Actually, you can just do it in the Inspector. Select the texture and change the mode. Then you don't have to do it in code.

avatar image BuzzKillingtonIII · Jan 17, 2014 at 05:25 PM 0
Share

I cant seem to find that option. Where should it appear? Its probably just me being a bit silly.

avatar image robertbu · Jan 17, 2014 at 05:27 PM 0
Share

In your Project folder, select your texture (not the material).

avatar image BuzzKillingtonIII · Jan 17, 2014 at 06:40 PM 0
Share

Found it. As i said, me being silly. 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

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

Reflective/refractive 2D material, like static water. 0 Answers

Background Bitmap 3 Answers

Scrolling background help - seams appearing... 1 Answer

2D Level Design (programmatically or not) 1 Answer

Changing physical material impossible? 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