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 DMCH · Nov 25, 2012 at 03:03 PM · 2dresolutionstandalone

Pong: Placing Gameobjects in a way that will work with any resolution

Hello,

I've just finished making a pong clone in 1024*768. When I build the game, in most resolutions, a wider screen area is being displayed than in the game's native resolution. In particular, varying amounts of space behind the paddles is being displayed.

I'd like some way to make the game consistent across resolutions. I've started by trying to scale the walls (thin horizontal cubes at the top and the bottom of the screen, for the balls to bounce off), but it doesn't seem to be working. This is the script I'm attaching to the walls:

 using UnityEngine;
 using System.Collections;
 
 public class ScaleScript : MonoBehaviour 
 {
     public GameObject attached;
     
     // Use this for initialization
     void Start () 
     {
         // Get the gameobject this script is attached to
         attached = this.gameObject;
         
         // Get the scale of the attached gameobject
         Vector3 scale = attached.transform.localScale;
         
         // Multiply the scale by the screenWidth divided by the native Screen Width
         scale.x = scale.x * (IntroGui.screenWidth/1024);
         
         // Resize the attached gameobject's transform
         transform.localScale = scale;
         
     }
     
 }
Comment
Add comment · Show 6
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 Fattie · Nov 25, 2012 at 03:05 PM 0
Share

you tell nothing about whether this is 2.5D or whatever

in any event, essentially, you have to work in "fractions of the screen width/height". OR you have to really clearly work in the UNITY WORLD SPACE, and ensure the camera is right each time.

it's a real nuisance really !

avatar image DMCH · Nov 25, 2012 at 03:28 PM 0
Share

It's just regular top-down 2d. I'm not sure how to position objects relative to screen width - so far I have only been using the transform's position.

avatar image Fattie · Nov 25, 2012 at 03:30 PM 0
Share

O$$anonymous$$, go to the doc and search on" "world to screen"

unity makes it easy !

avatar image DMCH · Nov 25, 2012 at 03:31 PM 0
Share

Thanks, will check it out!

avatar image Frix · Nov 25, 2012 at 03:33 PM 0
Share

I'm not 100% sure on this answer, but I've been experimenting with stuff like this, and I know my way isn't perfect, but it's getting there. You need to play around with positions such as 'Screen.height' and 'Screen.width'. If you want something in the middle, it would be something along the lines of

GUI.Label(Rect(Screen.height/2, Screen.width/2, 100, 100), "Hi");

It's not perfect, all you really need to do is play around with the 'Screen.' thingies. I didn't post this as an official answer because I'm obviously not 100% sure.

Show more comments

1 Reply

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

Answer by DMCH · Nov 25, 2012 at 07:17 PM

I found this when looking around. Does a fairly good job of explaining and provides code for different aspect ratios. Might be some use to the next guy!

http://gamedesigntheory.blogspot.ie/2010/09/controlling-aspect-ratio-in-unity.html

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

11 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

Related Questions

Once more with the Aspect Ratio's 1 Answer

Physic function doesn't work in different resoultions 0 Answers

Why my 2D shadows have low resolution? 0 Answers

gui texture different scale in full screen game. 1 Answer

2D Animation does not start 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