Uniy3D-重新缩放具有不同屏幕尺寸的GameObject

时间:2018-08-30 11:14:15

标签: c# unity3d

我正在开发Android游戏,2D平台游戏,但目前,我已使游戏只能在3:4屏幕上运行。我想一次重新缩放所有GameObject,我想知道是否可以将所有GameObjects放入一个空的GameObject,然后重新缩放该空的GameObject是否可行。会是个好主意吗?

此外,我目前正在对所有游戏对象进行一次缩放,这似乎可行,但是我认为这不是最实用的想法。

如果您还有其他建议,我会推荐。

这是我的代码,现在是我的GameManager脚本。

 `void Start()
  {
      //Getting the screen aspect
      float aspect = (float)Screen.width / (float)Screen.height;

      //Main aspect is 3:4 or 0.75f
      //Getting the new Scale on X and Y for GameObject 1, 2 and 3
      platformScaleX = (aspect * platformMainScaleX) / mainAspect
      trapsScaleX = (aspect * platformMainScaleX) / mainAspect;
      trapsScaleY = (aspect * platformMainScaleX) / mainAspect;

      //Getting the new position of the GameObject on X for the GameObjects 
      //that are on left and right because i want to move them to the 
      //center.
      trapsXleft = (aspect * platformMainPositionX) / mainAspect;
      trapsXright = (aspect * platformMainPositionX) / mainAspect;

      //Applying the new Scale on X for GameObject1
      platforms.transform.localScale = new Vector3(platformX, 1f, 1f);

      //Applying the new Scale on X and Y for GameObject 2 and 3
      leftTraps.transform.localScale = new Vector3(trapsScaleX, 
      trapsScaleY);
      rightTraps.transform.localScale = new Vector3(trapsScaleX, 
      trapsScaleY);

      //Setting the new position of GameObject 2 and 3
      leftTraps.transform.position = new Vector3(trapsXleft, 2.35f, -0.5f);
      rightTraps.transform.position = new Vector3(trapsXright, 4.36f, 
     -0.5f);
 }`

0 个答案:

没有答案