简体   繁体   English

Unity的扩展问题

[英]Scaling issues with Unity

I am trying to get the starting paddle (I am creating pong) to be at the left most of the screen at all times. 我一直在尝试使起始桨(我正在创建乒乓球)始终位于屏幕的最左侧。 I am having trouble coming up with a good formula for doing this. 我很难为此提供一个好的公式。 My camera size is 5, it is centered at (0,0). 我的相机尺寸为5,以(0,0)为中心。 The paddle should be at approximately -6.5 for the x-coordinate. 对于x坐标,桨叶应该大约为-6.5。 Here, in the script for the paddle, is how I am trying to do this 在这里,在桨脚本中,我是如何尝试执行此操作的

    //renderer is the SpriteRenderer
    xPos = -Camera.main.orthographicSize - 
        (renderer.sprite.textureRect.width/ renderer.sprite.pixelsPerUnit);

However this results in this (the left paddle is here the code is being applied): 但这会导致这种情况(在此处使用了左侧拨片的代码):

在此处输入图片说明

So, the right paddle is essential being placed at the very left - the width of the image. 因此,必须将右拨片放置在最左侧-图像的宽度。 However, some of the paddle image is cut off. 但是,某些桨图像被切除。 I can't seem to figure out why and I have checked everywhere. 我似乎无法弄清楚为什么,而且我到处都检查过。 Any help would be extremely appreciated and noticed. 任何帮助将不胜感激和关注。

I think your problem is related to the calculation of the width of the screen. 我认为您的问题与屏幕宽度的计算有关。

Unity uses Camera.main.orthographicSize to calculate the screen's height and then calculates the width depending on the screen proportions. Unity使用Camera.main.orthographicSize计算屏幕的高度,然后根据屏幕比例计算宽度。 Try to calcule the width in this way: 尝试以这种方式计算宽度:

width= Camera.main.orthographicSize * Camera.main.aspect; width = Camera.main.orthographicSize * Camera.main.aspect;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM