我正在努力做到這一點,以便當您通過向上或向下移動我的一個專案來滾動相機“縮放”時。但是每當我運行它時,我都沒有收到任何錯誤,但我根本無法移動它。這是我的代碼。
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public float MaxZoom;
public float MinZoom;
public float ZoomSpeed;
Vector3 p = new Vector3(0,0,0);
// Start is called before the first frame update
void Start()
{
Vector3 p = transform.position;
p.y = MaxZoom;
}
// Update is called once per frame
void Update()
{
Debug.Log(Input.mouseScrollDelta.y);
p.y = Input.mouseScrollDelta.y * ZoomSpeed;
if (p.y > MinZoom)
{
p.y = MinZoom;
}
if (p.y < MaxZoom)
{
p.y = MaxZoom;
}
}
}
uj5u.com熱心網友回復:
您沒有將 Vector3 應用于transform.position. 另外,夾緊方式不對,可以簡單地夾緊Mathf.Clamp()
void Update()
{
Debug.Log(Input.mouseScrollDelta.y);
p.y = Input.mouseScrollDelta.y * ZoomSpeed;
p.y = Mathf.Clamp(p.y, MinZoom, MaxZoom); // clamp
transform.position = p; // apply new position to transform
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/408554.html
標籤:
上一篇:為什么我的播放器后退比前退快
