[Unity基础]对Rotation的一些理解与实例(二)
2015-03-07 14:17
309 查看
第一人称相机观察:
物体平滑自转90度:
using UnityEngine; using System.Collections; //第一人称相机观察 public class CameraObserve : MonoBehaviour { // Update is called once per frame void Update () { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); //要么上下观察,要么左右观察 if (Mathf.Abs(mouseX) > Mathf.Abs(mouseY)) transform.eulerAngles += new Vector3(0, mouseX, 0); else transform.eulerAngles += new Vector3(-mouseY, 0, 0);//摄像机绕x轴旋转的方向跟鼠标y移动方向相反 } }
物体平滑自转90度:
using UnityEngine; using System.Collections; //物体平滑自转90度 public class RotateSelf : MonoBehaviour { bool isRotateSelf = false; Vector3 targetEuler = Vector3.zero; // Update is called once per frame void Update () { if (Input.GetKeyDown(KeyCode.R)) { isRotateSelf = true; targetEuler = transform.eulerAngles + new Vector3(0, 90, 0); } if (Input.GetKeyDown(KeyCode.T)) isRotateSelf = false; //平滑转90度 if(isRotateSelf) transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetEuler), Time.deltaTime); } }
相关文章推荐
- [Unity基础]对Rotation的一些理解与实例(一)
- [Unity基础]对Time.timeScale的一些理解
- [Unity基础]对Coroutine的一些理解
- [Unity基础]对Camera组件属性的一些理解
- 【Unity3D基础教程】给初学者看的Unity教程(六):理解Unity的新GUI系统(UGUI)
- [Unity基础]一些算法
- [基础知识] Unity 应用程序的一些方法
- java内接口,抽象类,继承实现的一些基础知识和实例
- JAVA基础之理解JNI原理(java方式实现dll实例)
- 学JavaWeb一年,小谈一些基础知识的理解
- 对汇编中一些基础知识的理解
- 理解S3C2440里面*.S文件的一些基础
- 菜鸟级别的一些最基础的linux命令实例详解
- Java基础的一些简单实例
- JSTL标签库的一些基础实例
- 对C语言中指针的理解与其基础使用实例
- unityshader固定管线的一些概念理解
- 最大熵模型的理解(一些实例的手动计算)
- JAVA基础知识: 对synchronized(this)的一些理解
- [unity基础教程]全面理解Unity加载和内存管理