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
3
Question by bruu · Feb 23, 2014 at 09:51 PM · loopbackgroundendless runner

Endless 2D background

Hello, I'm creating a flappybird clone and working on creating an endless background.

The way I have done it is I have a 'Trigger Manager', which has 2 trigger colliders as its child. One that triggers once the player collides, and this instantiates the background . The next trigger uses waitsforseconds and then deletes the previous prefab.

Is there a better way to have a endless background? My method is running into major issues.

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 · Feb 23, 2014 at 11:06 PM 0
Share

If your background can be represented by a single tile that repeats (i.e. the left side tiles with the the right side), then using $$anonymous$$aterial.SetTextureOffset() is a simple way to create an endless scrolling background. There is a bit of example code in the reference:

https://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$aterial.SetTextureOffset.html

4 Replies

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

Answer by aled96 · Jul 23, 2014 at 08:53 AM

Watch this video, it can help you I think :)

https://www.youtube.com/watch?v=9bhkH7mtFNE

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 JadsonAlmeida · Apr 16, 2015 at 12:31 AM 0
Share

Very nice explanation!

avatar image Al-Maliki · Jan 12, 2018 at 03:24 PM 0
Share

thanks .................

avatar image
4
Wiki

Answer by king_ · Apr 01, 2014 at 06:05 PM

if anyone still looking for an answer i've my own short script,without instantiating the background,use two backgrounds and attach this BackGrounScript to both backgrounds and set the width of the BG in the inspector panel for both BG(width must be in unity units)


UPDATE


now you can use this for endless y axis back ground

  • for y axis endless BG set the height of your BG in the inspector(set width to 0)

  • for x axis endless BG set the width of your BG in the inspector(set height to 0)



    using UnityEngine;

    public class BackGroundScript : MonoBehaviour { private Vector3 backPos; public float width = 14.22f; public float height = 0f; private float X; private float Y;

       void OnBecameInvisible()
         {
             //calculate current position
             backPos = gameObject.transform.position;
             //calculate new position
             print (backPos);
             X = backPos.x + width*2;
                 Y = backPos.y + height*2;
             //move to new position when invisible
             gameObject.transform.position = new Vector3 (X, Y, 0f);
         }
     
     }
    
Comment
Add comment · Show 1 · 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 matheusouzatj · Feb 05, 2020 at 10:52 AM 0
Share

Tried it, nothing happend. The OnBecameInvisible is not called even when the background is not appearing in the screen anymore :/

avatar image
2

Answer by zee_ola05 · Feb 23, 2014 at 10:37 PM

Just create 2 background sprites (should be looping, ofcourse) and change the position based on what the camera sees.

Do not instantiate many background sprites. 2 is usually enough. Just recycle them.. do not destroy/initialize.

Comment
Add comment · Show 1 · 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 bruu · Feb 24, 2014 at 10:32 AM 0
Share

Thanks for the reply,

How could i go about doing this roughly? How do I calculate what the camera sees etc?

avatar image
0

Answer by j4ke · Feb 05, 2020 at 02:32 PM

You have seen this tutorial?

https://learn.unity.com/tutorial/live-session-making-a-flappy-bird-style-game#5c7f8528edbc2a002053b6a7

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

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

Related Questions

Looping background 1 Answer

how to stop certain objects from looping in bg looper differently from your background 1 Answer

Background Sprite Setting 0 Answers

Resolution independent background for a 2d game 1 Answer

Setting Background using NGUI 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