【发布时间】:2015-05-04 14:37:38
【问题描述】:
我正在尝试在 Unity 中使用 box collider 功能,但它似乎已被弃用。
我收到消息:
"UnityEngine.BoxCollider2D.center" is obsolete. BoxCollider2D.center has been deprecated. Use BoxCollider2D.offset instead (UnityUpgradable)
我一直在尝试在屏幕边缘设置墙。这是代码:
//Move each wall to its edge location:
topWall.size = new Vector2 (mainCam.ScreenToWorldPoint (new Vector3 (Screen.width * 2f, 0f, 0f)).x, 1f);
topWall.center = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3 ( 0f, Screen.height, 0f)).y + 0.5f);
bottomWall.size = new Vector2 (mainCam.ScreenToWorldPoint (new Vector3 (Screen.width * 2, 0f, 0f)).x, 1f);
bottomWall.center = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3( 0f, 0f, 0f)).y - 0.5f);
leftWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height*2f, 0f)).y);;
leftWall.center = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).x - 0.5f, 0f);
rightWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height*2f, 0f)).y);
rightWall.center = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width, 0f, 0f)).x + 0.5f, 0f);
//Move the players to a fixed distance from the edges of the screen:
Player01.position.x = mainCam.ScreenToWorldPoint (new Vector3 (75f, 0f, 0f)).x;
Player02.position.x = mainCam.ScreenToWorldPoint (new Vector3 (Screen.width -75f, 0f, 0f)).x;
TopWall、BottomWall、LeftWall 和 RightWall 当然都是 BoxCollider2D 类型。
我应该如何更改我的代码以免收到此错误消息?感谢您的帮助。
【问题讨论】:
标签: unity3d 2d deprecated obsolete