/***
* Title:"XXX" 项目
* 主题:XXX
* Description:
* 功能:XXX
* Date:2018
* Version:0.1版本
* Author:Coffee
* Modify Recoder:
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace SimpleUIFrame
{
public class Test_EffectUI : MonoBehaviour
{
public GameObject EquipmentCamera;
Vector3 range = new Vector3(4f, 3f,3F); // 定义一个二维向量
Quaternion mStart; // 四元数
Vector2 mRot = Vector2.zero;//旋转
// Use this for initialization
public float offsetX=5.0F;
void Start()
{
mStart = transform.localRotation; // 获取当前组件的本地旋转四元数
}
private void Update()
{
//Vector3 fwd = EquipmentCamera.transform.forward;
//fwd.Normalize();
//Vector3 vaxis = Vector3.Cross(fwd, Vector3.right);
//transform.Rotate(vaxis*0.05F, -Input.GetAxis("Mouse X"), Space.World);
//Vector3 haxis = Vector3.Cross(fwd, Vector3.up);
//transform.Rotate(haxis*0.05F, -Input.GetAxis("Mouse Y"), Space.World);
TransformTrans();
}
public void TransformTrans()
{
Debug.Log("开始鼠标晃动");
Vector3 pos = Input.mousePosition*5F; // 获取鼠标位置
float halfWidth = Screen.width * 0.5f; // 相对原点x
float halfHeight = Screen.height * 0.5f; // 相对原点y
float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, 5f, -5f); // 返回一个【-1,1】的x值
float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f); // 返回一个【-1,1】的x值
//基于浮点数t返回a到b之间的插值,t限制在0~1之间。当t = 0返回from,当t = 1 返回to。当t = 0.5 返回from和to的平均值
// Quaternion.Euler(new Vector3()) 返回一个旋转角度,绕z轴旋转z度,绕x轴旋转x度,绕y轴旋转y度(像这样的顺序)。
mRot = Vector2.Lerp(mRot, new Vector3(x, y,0), Time.deltaTime*1); // 插值运算
Debug.Log(mRot);
this.gameObject.GetComponent
this.gameObject.GetComponent
//transform.localPosition= new Vector3(,0,0);
transform.localRotation = mStart * Quaternion.Euler(mRot.y * range.y, -mRot.x * range.x, 0);
}
}
}
https://blog.csdn.net/yguoelect/article/details/72523105