Unity C# 相机移动
Unity C# camera movement
我目前正在尝试为统一创建一个相机控件(跟随预制件并能够缩放等...
I am very new to C#
我在使用此脚本时遇到的一个问题是
- 相机缩放到 0,0,0。 (当我需要它停留在当前的 Y 轴上时,我尝试更改 void "Move()" 但向量需要 3 m_....'s
I also need to write a piece of code that will allow the player to zoom the camera in and out using the
scroll wheel... (In "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;
}
要使相机保持在 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);
为了缩放相机,您需要 add/subtract 将值设置为正交而不是简单地设置它:
// Zoom in
Camera.main.orthographicSize -= 4.8f;
// Zoom out
Camera.main.orthographicSize += 4.8f;
我目前正在尝试为统一创建一个相机控件(跟随预制件并能够缩放等...
I am very new to C#
我在使用此脚本时遇到的一个问题是
- 相机缩放到 0,0,0。 (当我需要它停留在当前的 Y 轴上时,我尝试更改 void "Move()" 但向量需要 3 m_....'s
I also need to write a piece of code that will allow the player to zoom the camera in and out using the scroll wheel... (In "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;
}
要使相机保持在 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);
为了缩放相机,您需要 add/subtract 将值设置为正交而不是简单地设置它:
// Zoom in
Camera.main.orthographicSize -= 4.8f;
// Zoom out
Camera.main.orthographicSize += 4.8f;