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 FritzPeace · Apr 18, 2015 at 11:54 PM · c#2d2d-platformerbackground

Making background move and loop

Hello guys,

I tried to find a solution for my problem, so these were the two I got. The first one was to create a quad, etc. I did not like it because I have a background sprite that covers the screen almost perfectly (it is a bit bigger).

What I did is to have 2 backgrounds, simple sprites that will rotate, but I get sometimes the problem of a blackline moving between the sprites. I would like to know how to fix this problem. I have tried to do it, with a code, but It worked half of the times. Sometimes the bug appeared, sometimes it didn't.

My camera does not move.

Here is my code using UnityEngine; using System.Collections;

 public class MoveBackground : MonoBehaviour {

 public float speed = 2;
 public float maxSpeed = 0.5f;
 private float speedscoreadd;
 private float getBGspeed;
 public float leftmax = 12;
 //private int spriteNum;
 public string levelDestroy;
 public Vector3 rightspawn = new Vector3(12.5f, 0f, 1f);
 private GameObject otherBG;
 private ScoreKeeper scoreKeeper;
 //public Sprite[] bgSprites;

 Vector3 backgroundPos;
 Vector3 otherBGPos;

 // Use this for initialization
 void Start () {
     scoreKeeper = GameObject.Find ("ScoreKeeper").GetComponent<ScoreKeeper>();
     if(this.name == ("Game Background 1")){
         otherBG = GameObject.Find ("Game Background 2");
         if (otherBG.name == "Game Background 2"){
             Debug.Log ("Got Background 2 successfully");
         }else{
             Debug.Log ("I did not find the Second Background");
         }
     }
     if(this.name == ("Game Background 2")){
         otherBG = GameObject.Find ("Game Background 1");
         if (otherBG.name == "Game Background 1"){
             Debug.Log ("Got Background 1 successfully");
         }else{
             Debug.Log ("I did not find the First Background");
         }
     }
 }
 // Update is called once per frame
 void FixedUpdate () {
     if (Application.loadedLevelName == (levelDestroy)){
         Destroy(this);
         Debug.Log("Destroying duplicate instance");
     }else{
         DontDestroyOnLoad(this);
     }

// speedscoreadd = scoreKeeper.score * 0.001f ; // if (speedscoreadd >= maxSpeed - speed) { // speedscoreadd = maxSpeed; // } // getBGspeed = -speed - speedscoreadd; // Debug.Log ("Speed background is:" + getBGspeed); transform.position += new Vector3( -speed - speedscoreadd,0,0); backgroundPos = this.transform.position; if (backgroundPos.x <= leftmax) { //spriteNum = Random.Range(0, 3); //this.GetComponent().sprite = bgSprites[spriteNum]; otherBGPos = new Vector3(otherBG.transform.position.x, 0, 0); if (otherBGPos.x <= 0){ Debug.Log ("Smaller"); this.transform.position = rightspawn + otherBGPos; }else if (otherBGPos.x > 0){ Debug.Log ("Bigger"); this.transform.position = rightspawn - otherBGPos; } } } }

If necessary I can send screen shots of how I made it all. I would really like some help,

Thanks in advance, Fritz

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

In my 2D platformer game, how would I create a height marker?, 1 Answer

How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer

Change the background color attribute of a camera in C#? 2 Answers

2D character gets stuck when falling 1 Answer

I cant get wall jumping to work in my 2D platformer (C#) 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