using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
[Header("速度")]
public float mSpeedVal = 5.0f;
public Transform mTarget;//目标
// Update is called once per frame
void Update()
{
ViewControll();
}
/// <summary>
/// 鼠标输入
/// </summary>
void ViewControll()
{
//左键控制上下左右移动
if (Input.GetMouseButton(0))
{
float Horizontal = Input.GetAxis("Mouse X");
float Vertical = Input.GetAxis("Mouse Y");
Camera.main.transform.Translate(-Horizontal * mSpeedVal * Time.deltaTime * 0.5f, 0, 0);
Camera.main.transform.Translate(0,-Vertical * mSpeedVal * Time.deltaTime * 0.5f, 0);
}
//右键控制上下左右旋转
if (Input.GetMouseButton(1))
{
float Horizontal = Input.GetAxis("Mouse X");
float Vertical = Input.GetAxis("Mouse Y");
Camera.main.transform.RotateAround(mTarget.position,Vector3.up, Horizontal);
Camera.main.transform.RotateAround(mTarget.position,Vector3.left, Vertical);
}
//鼠标滚轮控制靠近和拉远距离
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
Camera.main.transform.Translate(-Camera.main.transform.forward * Input.GetAxis("Mouse ScrollWheel") * mSpeedVal * Time.deltaTime * 10);
}
}
}
鼠标控制摄像机
猜你喜欢
转载自blog.csdn.net/qq_41692884/article/details/85234678
今日推荐
周排行