Unity 准心和视角旋转

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 视角移动
/// </summary>
public class CameraCollider : MonoBehaviour
{
public Camera cameragame;
// Start is called before the first frame update
void Start()
{

}
public float inputspeed=1f;//控制键速度
// Update is called once per frame
void Update()
{
float X = (Input.mousePosition.x - Screen.width / 2f)/(Screen.width/2);
float Y = (Input.mousePosition.y - Screen.height / 2f)/(Screen.height/2);


cameragame.transform.Rotate(Vector3.left*Y* inputspeed);//摄像机上下旋转

transform.Rotate(Vector3.up * X* inputspeed);//角色左右旋转
cameragame.transform.eulerAngles = new Vector3(cameragame.transform.eulerAngles.x,cameragame.transform.eulerAngles.y,0);//锁定自旋转
}

}

代码

 

 

 

加一个3D图片 在摄像机前面

 

posted @ 2020-07-08 00:41  手札记  阅读(638)  评论(0编辑  收藏  举报