在Unity中更改已弃用的代码段(BoxCollider2D)

时间:2015-05-04 14:37:38

标签: unity3d 2d deprecated obsolete

我正在尝试使用Unity中的box collider功能,但它似乎已被弃用。

我收到消息: //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;

我一直试图将Walls设置在屏幕的边缘。这是代码:

TopWall

BottomWallLeftWallRightWallBoxCollider2D当然都属于Item.aggregate([ { $unwind: '$dummy'}, { $match: {'dummy.storage': {$gt: 0}} }, { $group: {_id: '$_id', dummy: {$push: '$dummy'}, original_y: { $first: "$original_y" }, new_y: { $first: "$new_y" }, }}, {$project:{ original_y: 1, new_y: 1, tallyAmount: {$sum: ["$new_y","$original_y"] } } }, ] ) .exec(function(err, results){ if(err) { console.log("Error : " + err); return res.json ({error: "Error"}); } else if(!(results) || results == null || results.length == 0) { console.log("No Results Found"); return res.json ({error: "No Results Today"}); }else{ res.send(results); } }); 类型。

如何更改代码以避免收到此错误消息?谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

" BoxCollider2D.center已被弃用。请改用BoxCollider2D.offset"

替换:

topWall.center = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3 ( 0f, Screen.height, 0f)).y + 0.5f);

使用:

topWall.offset = new Vector2 (0f, mainCam.ScreenToWorldPoint (new Vector3 ( 0f, Screen.height, 0f)).y + 0.5f);

当然,这也会改为BottomWall,LeftWall和RightWall。