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
0
Question by plaguebreath · Oct 08, 2017 at 04:19 PM · androiduiscreen resolution

Trouble on resize screen and anchor ui in android based version of Space Shooter tutorial

Hello everyone, I am new of Unity so I am try to learn from tutorials, so I did the space shooter one and made some change and I did try to deploy on my phonem not an Apple one, it's an android one. So basically when I build and run it the are of the screen it's cut on the two side so I did try some answer on the web and I found a script for resize the camera on start based on the resolution of screen. It's working but it's not what I need I guess because the anchor of my labels and button are not connected with the camera but on the screen size, I'm right ? So what I shall do to make my UI and my screen resolution resize cuttectly for my android test project ? Thank you everyone fot the help.

Comment
Add comment · Show 2
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 Mehrdad995 · Oct 08, 2017 at 04:33 PM 0
Share

Hi! can you upload an image of your issue please? all I know is that if the UI is working properly on Standalone version and the canvas scaler has been set to "Scale with screen size" then all you have to do is to lock screen aspect ratio to the one you are using on your desktop. they are usually 16:9 which means the with is 1.7777 times bigger than height. thus you have to use something like this on awake: Screen.height = Screen.width*9/16 -(equal to 0.5625)-.

avatar image plaguebreath Mehrdad995 · Oct 08, 2017 at 04:53 PM 0
Share

Thank you, as you can see on the image the spacesheep in my phone on bottom right went out of screen limit, while on pc it not happen at all, the screen size is set to 600x900 on the Unity, so what you suggest I shall do ?alt text alt text

2017-10-08-18-44-32.jpg (201.0 kB)
cattura.png (44.6 kB)

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mehrdad995 · Oct 09, 2017 at 02:07 PM

Ok, just downloaded the project to make sure what the exact problem is.

by default the game run at landscape ratio on your desktop

so I just changed the aspect ratio of the game window to 9:16 to simulate portrait mobile screen.

(you can add one by yourself if there isn't any 9:16)

alt text

then the same thing happened to me as well! the spaceship could get off of the screen border.

it's not related to UI things at all, but the camera itself.

so all you have to do is to just change the MainCamera orthographic size to something bigger.

now in my case if I change the orthographic size to 13.2 everything gonna get fixed!

alt text


help-01.jpg (36.5 kB)
help-03.jpg (173.7 kB)
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 plaguebreath · Oct 09, 2017 at 08:50 PM 0
Share

First of all thank you for the help, I follow the explanation but still had no time to try it, so basically what I was thinking was true, the problem was the main camera but then if I do as you suggest this fix will work with all the possible device with Android ? The ancor of the Canvas is not refer to the viewport ? Or they are refered to the maincamera only ? Thank you.

avatar image
0

Answer by plaguebreath · Oct 09, 2017 at 10:09 PM

Sorry my friend @Mehrdad995 but I think there is something not work yet, I did what you suggested me but it play in weird way now. No more the ship go off the screen but now the spawn point of the enemy is more down then normal and my ship can't move backward of almost same size as show in second image with red color. While on first pic the movement on the up and down screen of the ship is correct as well as per enemy.


pix1.jpg (142.1 kB)
pix2.jpg (135.3 kB)
Comment
Add comment · Show 5 · 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 Mehrdad995 · Oct 10, 2017 at 11:43 AM 0
Share

then all we have to do is altering values. there are 4 main things that you can change to get an appropriate behavior from your game.

1) although in my case the black part of the game view get fixed automatically once the game is played, but you can just move the camera a little bit lower to overcome that issue.

2) on game controller script, there is a variable named "spawn values", it deter$$anonymous$$es where the obstacles and enemies should be spawned on the range of (-x,x) on the X axis, and constant (y) and (z) on the Y & Z axis.

3) boundary game object has a box collider which defines where all obstacles and things should be destroyed upon exiting the area of its boundary, so by just changing its size you can define where everything should be destroyed.

4) on player script, there is a part named "boundary", it defines player's movement limits. so bigger number on each axis means bigger area it can surf. please note that the player boundary should always be smaller than destroyer boundary or else the player itself gonna get destroyed if get outside of it.

alt text

my suggestion is to keep the background bigger that the camera boundary so no one will see black screens on different aspect ratios.

avatar image plaguebreath Mehrdad995 · Oct 10, 2017 at 04:07 PM 0
Share

Thank you my friend for follow my topic, yes i undertsand all the values you suggest me to change, I had idea to change the bound and destruction area but I was guessing It would be some kind of absolute value connected to resolution of my screen and so I was guessing that as soon as I can change the resolution of my viewport I shall get all the numbers fixed and it would be compatible with all the tablets and android smartphone for every resolution. But seems I was wrong on guessing it or maybe I not understand well all the resize stuff because I'm just learning now the unity engine.

avatar image Mehrdad995 plaguebreath · Oct 10, 2017 at 05:27 PM 0
Share

It's possible to alter all those values at run-time for each screen and device. however it gonna be the hard way, personally I prefer to take the simpler solution and fake it out, how? i.e just make the spawn point far enough that with no screen ration, its possible to see things spawn suddenly. but if you want to take the harder solution which is also a more precise way to guarantee that everything gonna be ok, then it would be like so: for example imagine if I'm wanted to change the collider size base on the screen ratio then I have to make an script which gonna set the size base on ratio (definitely :P), the code would be like: (originally taken from here)

 void Start ()
 {
      float height = Camera.main.orthographicSize * 2.0f;
      float width = height * Screen.width / Screen.height;
      myCollider.size = Vector3(width, height, 0.1f);
  }

for other scripts variables, you can either implement this part in each script you want to change it's values, or grab wanted script value from a different script and change it in there. plus, if you wanted to have higher or lower values than the width or height you should multiply them with an other number.

Show more comments
avatar image
0

Answer by plaguebreath · Oct 14, 2017 at 04:36 PM

So after little try I end up choosing another solution, basically I think I have to test the Camera size with the width of my background object and if the camera is bigger then my background I must set my Xmin Xmax to -7 and 7 otherwise must make some adjustment if the camera is smaller. The questio is now, how to compare the size of the background mesh to my camera ? I could show the resolution in pixel if camera but how to compare with the background ? Sorry for noob question but I am try to understand it better.

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

189 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 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 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 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 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 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 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

For Scale with sreen size for canvas in unity3d, my sprites in Ui are pixelated when used for larger sceens 0 Answers

UI joystick changes place after screen orientation 1 Answer

Unity 4.6 Android changing quality level during runtime 1 Answer

How do i make my ui elements stay the same size and position on all andorid devices? 1 Answer

Search for movies and shows from Netflix, Hulu, Amazon Video, etc. 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