Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Stormize · Sep 20, 2015 at 07:20 PM · c#android2d gamecamera viewportbeginners

How to fix bold black bars on right side of the Game (on any device)

I am trying to create an endless runner. I have already created a system to generate infinite backgrounds from an array of some. However, on running the game, I get huge black bar on the right side of the screen, both on PC and on Android phone.

Here are the screenshots : (On PC - In Unity Game Preview) alt text

(On Android device) alt text

One more thing, on Android, it doesn't even display the left side of the game, i.e, where the character is. It looks like the things are displaced towards left.

Also, the game is a scrolling on and everything is scrolling but behind that bar. It just doesn't go.

I hope I can get some help. Ask me if you need any piece of code.

Here are two scripts which I think might have the bug.

"CameraFollow" script

  using UnityEngine;
 using System.Collections;
 
 public class CameraFollow : MonoBehaviour {
 
     public GameObject targetObject;
     private float distanceToTarget;
 
     // Use this for initialization
     void Start () {
         distanceToTarget = transform.position.x - targetObject.transform.position.x;
 
     }
 
     // Update is called once per frame
     void Update () {
 
 
         float targetObjectX = targetObject.transform.position.x;
 
         Vector3 newCameraPosition = transform.position;
         newCameraPosition.x = targetObjectX + distanceToTarget;
         transform.position = newCameraPosition;
     }
 }


My "GeneratorScript"

  using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class GeneratorScript : MonoBehaviour {
 
     public GameObject[] availableRooms;
 
     public List<GameObject> currentRooms;
 
     private float screenWidthInPoints;
 
 
 
 
 
     // Use this for initialization
     void Start () {
         float height = 0.0f * Camera.main.orthographicSize;
         screenWidthInPoints = height * (Camera.main.targetDisplay);
     }
 
     // Update is called once per frame
     void Update () {
 
     }
 
     void FixedUpdate()
     {
         GenerateRoomIfRequred ();
     }
 
     void AddRoom(float farhtestRoomEndX)
     {
         int randomRoomIndex = Random.Range (0, availableRooms.Length);
 
         GameObject room = (GameObject)Instantiate (availableRooms [randomRoomIndex]);
 
         float roomWidth = room.transform.FindChild ("floor").localScale.x;
 
         float roomCenter = farhtestRoomEndX + roomWidth * 3.0f;
 
         room.transform.position = new Vector3 (roomCenter, 0, 0);
 
         currentRooms.Add (room);
     }
 
     void GenerateRoomIfRequred()
     {
         //1
         List<GameObject> roomsToRemove = new List<GameObject>();
 
         //2
         bool addRooms = true;        
 
         //3
         float playerX = transform.position.x;
 
         //4
         float removeRoomX = playerX - screenWidthInPoints;        
 
         //5
         float addRoomX = playerX + screenWidthInPoints;
 
         //6
         float farhtestRoomEndX = 0;
 
         foreach(var room in currentRooms)
         {
             //7
             float roomWidth = room.transform.FindChild("floor").localScale.x;
             float roomStartX = room.transform.position.x - roomWidth * 6.0f;    
             float roomEndX = roomStartX + (roomWidth * 13.0f);                            
 
             //8
             if (roomStartX > addRoomX)
                 addRooms = false;
 
             //9
             if (roomEndX < removeRoomX)
                 roomsToRemove.Add(room);
 
             //10
             farhtestRoomEndX = Mathf.Max(farhtestRoomEndX, roomEndX);
         }
 
         //11
         foreach(var room in roomsToRemove)
         {
             currentRooms.Remove(room);
             Destroy(room);            
         }
 
         //12
         if (addRooms)
             AddRoom(farhtestRoomEndX);
     }
 
 }

I tried playing with the numbers on GeneratorScript, but nothing seemed to help.

Also, I also tried changing aspect ratio and all that stuff, but the black bar seems to stay in place and everything else just changes. I don't know, I don't want to create a new Project and import everything there.

Can someone please give me a solution to this problem as soon as possible? Also, I am a beginner at game development and a designer by profession.

Thank you, Have a nice day!

ywegn.png (362.6 kB)
il1x2.jpg (125.7 kB)
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
1

Answer by BeGunity · Mar 20, 2017 at 01:24 AM

I'm having the exact same problem, 2 years on from this post. The 0 replies is daunting. Did you ever manage to resolve this?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Joystick movement Android 2D 0 Answers

How do you arrange sprites in order by name in Sprite atlas? 1 Answer

How can I force a device to recognize touches from large surfaces like the bottom of a hand? 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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