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 Dogg · Aug 19, 2014 at 07:44 PM · c#2dspritemoving

Moving A Sprite Then Returning It To Position?

How can I move a sprite/texture left for a couple of seconds or to a certain position, then return it back to it's original position(where it starts)? The reason I want to do this is because my background scrolls to the left, but when it scrolls off screen the scene background becomes blue and bland because the clouds have scrolled off screen. My texture that I have consists of clouds and a blue background, but it only looks like the clouds move so again they move off screen and reset but they take a while and I don't want to increase the speed of it because then it will look too fast.

So, my texture scrolls but doesn't actually move. I want something that will actually move my textures/sprites. If your curious as to how my background scrolls, here's my script:

 public class BackgroundScroller : MonoBehaviour {
 
     public float speed = 0;
     public static BackgroundScroller current;
 
     float pos = 0;
 
     void Start(){
         current = this;
     }
 
     void Update(){
         pos += speed;
         if(pos > 1.0f)
             pos -= 1.0f;
         renderer.material.mainTextureOffset = new Vector2(pos, 0);
     }
 }
 
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 haim96 · Aug 19, 2014 at 08:28 PM

Good tutorial about scrolling background.

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/2d-scrolling-backgrounds

there are several method there so you can pick the one that fits you.

Comment
Add comment · Show 2 · 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 Dogg · Aug 19, 2014 at 10:09 PM 0
Share

Thanks. I'll try and see which one works best.

avatar image Dogg · Aug 19, 2014 at 11:43 PM 0
Share

Well I tried the first method in the video, and I can't get it to work. It won't scroll my background or anything. That method out of the 3 is the best for me and what I'm looking for, but it's just not working for me. Isn't there a way that I can change my script that I posted to make it scroll like the first method in the link?

avatar image
1

Answer by smoggach · Aug 19, 2014 at 08:22 PM

Change the position or localPosition of the sprite's transform.

Comment
Add comment · Show 2 · 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 Dogg · Aug 19, 2014 at 10:08 PM 0
Share

Sorry but how and why? I just need a better understanding of it. I hope you can understand me and where I'm co$$anonymous$$g from.

avatar image smoggach · Aug 20, 2014 at 04:38 AM 0
Share

transform.position transform.localPosition

transform is your gameObject's position, rotation, and scale in the world.

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

23 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

I need a script in C# which moves an object in only one direction at a time. 1 Answer

How to Address Texture2D Elements from a Sprite with Sprite Mode: Multiple, in Code? 1 Answer

Sprite flip movement script not working! HELP! 0 Answers

Successfully transitioned idle-move animations. How to transition look left-right-up-down animations? 0 Answers

GetComponent().enabled = true; 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