我目前正在尝试创建一个统一的摄像头控制器(跟随预制件并能够进行缩放等等......
我是C#
的新手
我对此脚本的问题是
我还需要编写一段代码,允许玩家使用相机放大和缩小相机 滚轮...(在“Public Void Update()”中......
我一直在浏览指南和视频,找不到任何可以帮助我的东西..
private void FixedUpdate()
{
Move();
}
private void Move()
{
m_DesiredPosition = m_target.position;
transform.position = Vector3.SmoothDamp(transform.position,
m_DesiredPosition, ref m_MoveVelocity, m_DampTime);
}
public void Update()
{
// Get the scroll value of the mouse scroll wheel
// float scroll = Input.GetAxis("Mouse ScrollWheel");
// Is the scroll value not 0?
// Modify the orthographic size by the scroll value
Camera.main.orthographicSize = 4.8f;
}
答案 0 :(得分:4)
为了使相机保持在Y = 0,只需覆盖Y:
m_DesiredPosition = m_Target.position;
m_DesiredPosition.Y = 0;
transform.position = Vector3.SmoothDamp(transform.position,
m_DesiredPosition, ref m_MoveVelocity, m_DampTime);
要缩放相机,您需要将值添加/减去正交分析而不是简单地设置它:
// Zoom in
Camera.main.orthographicSize -= 4.8f;
// Zoom out
Camera.main.orthographicSize += 4.8f;