我已经看了几段视频并阅读了一些帖子,它们表明我可以在游戏中通过更改MainCamera(Unity 2D游戏,正交投影)的Size参数来缩放摄像机视图。这样做可以放大和缩小“场景视图”,但是我在Inspector中任何地方所做的更改都不会更改“游戏”视图。
有人可以建议吗?谢谢。
答案 0 :(得分:2)
正射影像大小定义了摄影机的观看量,并且只会缩放摄影机渲染的元素。您似乎正在尝试放大Canvas,但是UI元素呈现在整个场景的顶部。
要放大和缩小,您可以:
使用脚本可以放大画布,在此处查看:Pinch zoom on UI
public class PinchZoom : MonoBehaviour { public Canvas canvas; // The canvas public float zoomSpeed = 0.5f; // The rate of change of the canvas scale factor void Update() { // If there are two touches on the device... if (Input.touchCount == 2) { // Store both touches. Touch touchZero = Input.GetTouch(0); Touch touchOne = Input.GetTouch(1); // Find the position in the previous frame of each touch. Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; // Find the magnitude of the vector (the distance) between the touches in each frame. float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; // Find the difference in the distances between each frame. float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag; // ... change the canvas size based on the change in distance between the touches. canvas.scaleFactor -= deltaMagnitudeDiff * zoomSpeed; // Make sure the canvas size never drops below 0.1 canvas.scaleFactor = Mathf.Max(canvas.scaleFactor, 0.1f); } } }
希望这对您有帮助!