Unity中按自定义轴进行自转——Rotate浅谈

更新时间:2023-05-11 06:06:00 阅读: 评论:0

Unity中按⾃定义轴进⾏⾃转——Rotate浅谈
Rotate浅谈
最近做了太多关于⾃转的事情了,这下刚好弄个脚本,把情况都给总结⼀下,⾃⼰还可以⾃⼰选择⾃⼰想要的旋转轴,美滋滋,嘻嘻,对于⼀些⽐较刁钻的⾓度的花就需要⾃⼰在脚本上⾃⼰输⼊⼀下啦
废话不多说,上代码·······
代码清晰易懂,没有写太多注释
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum TypeAxis
{
x, y, z, outer, Middle,Inside,Custom
}
///
/// 根据哪个轴⾃转
///
public class RotateSelf : MonoBehaviour {
private Quaternion RotatePos;
public float SpeedStart;
public float SpeedBack;
public TypeAxis TA = TypeAxis.x;
public int X, Y, Z;
public bool SelfRotate = true;
void Awake()
{
RotatePos = transform.localRotation;
}
// Update is called once per frame
void FixedUpdate () {
if (SelfRotate == true)
{
switch (TA)
{
ca TypeAxis.x:
transform.Rotate(new Vector3(1, 0, 0) * Time.deltaTime * SpeedStart);
break;
ca TypeAxis.y:
transform.Rotate(new Vector3(0, 1, 0) * Time.deltaTime * SpeedStart);
break;
ca TypeAxis.z:
transform.Rotate(new Vector3(0, 0, 1) * Time.deltaTime * SpeedStart);
break;
ca TypeAxis.outer:
transform.Rotate(new Vector3(-1, -1, -1) * Time.deltaTime * SpeedStart);
break;
ca TypeAxis.Middle:
transform.Rotate(new Vector3(-1, -1, 1) * Time.deltaTime * SpeedStart);
break;
ca TypeAxis.Inside:
transform.Rotate(new Vector3(1, 1, 1) * Time.deltaTime * SpeedStart);
break;
ca TypeAxis.Custom:
transform.Rotate(new Vector3(X, Y, Z) * Time.deltaTime * SpeedStart);
break;
default:
break;
}
}
el
{
Quaternion  NewAngle = transform.localRotation ;
Quaternion  p = Quaternion.Lerp(NewAngle, RotatePos,Time.deltaTime * SpeedBack);        transform.localRotation = p;
}
}
}

本文发布于:2023-05-11 06:06:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/581496.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:没有   想要   脚本   情况
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图