首页 > 编程语言 > 详细

Unity 准心和视角旋转

时间:2020-07-08 09:35:59      阅读:139      评论:0      收藏:0      [点我收藏+]

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图片 在摄像机前面

技术分享图片

 

Unity 准心和视角旋转

原文:https://www.cnblogs.com/suiyi78/p/13264452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!