收藏 分享(赏)

实现物体绕不同轴旋转 并调用外部函数unity3d插件.doc

上传人:精品资料 文档编号:10295415 上传时间:2019-10-28 格式:DOC 页数:11 大小:33KB
下载 相关 举报
实现物体绕不同轴旋转 并调用外部函数unity3d插件.doc_第1页
第1页 / 共11页
实现物体绕不同轴旋转 并调用外部函数unity3d插件.doc_第2页
第2页 / 共11页
实现物体绕不同轴旋转 并调用外部函数unity3d插件.doc_第3页
第3页 / 共11页
实现物体绕不同轴旋转 并调用外部函数unity3d插件.doc_第4页
第4页 / 共11页
实现物体绕不同轴旋转 并调用外部函数unity3d插件.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、实现物体绕不同轴旋转 并调用外部函数第一个和第二脚本赋给目标物体;第三个脚本赋给任何一个物体作为测试物体使用。代码目的是方便外部调用和函数重用。注意 isRotating 参数的使用。第一个文件,声明枚举类型,分别为均匀变化和加速变化using UnityEngine;using System.Collections;public enum CTRotationTypeUniform,AccelerateUniformly第二个文件:主函数,实现围绕轴变化的两个函数,分别为均匀变化和加速变化using UnityEngine;using System.Collections;public cl

2、ass CTRotation : MonoBehaviour / Use this for initializationvoid Start () / Update is called once per framevoid Update () if (isRotating)executeRotate();bool isRotating = false;Quaternion definedRotation = new Quaternion(0, 0, 0,0);Vector3 rotateVector = new Vector3(1,0,0);float rotateVelocity = 0;f

3、loat accelerateDuration = 0;float leftDuration = 0;float rotateDuration = 0;int rotateAxis = 0;float angleRange = 0;float deltaRotate = 0;/0;/ acceleration when it is in the accelerating process.float rotateAcceleration = 0;CTRotationType rotateType;/int RotateType = 0;private void initRotateArgumen

4、t( float _initAngleRange, int _initRotateAxis, float _initRotateDuration)rotateAxis = _initRotateAxis;rotateDuration = _initRotateDuration;leftDuration = _initRotateDuration;angleRange = _initAngleRange;rotateType = CTRotationType.Uniform;public void RotateTo(float _angleRange, int _axis, float _dur

5、ation)print(“in the rotateto”);isRotating = false;rotateType = CTRotationType.Uniform;/RotateType = 0;initRotateArgument(_angleRange, _axis, _duration);switch(rotateAxis)case 0: /rotate around X axisrotateVector = Vector3.right;break;case 1:/rotate around Y axisrotateVector = Vector3.up;break;case 2

6、:/rotate around Z axisrotateVector = Vector3.forward;break;default:break;deltaRotate = angleRange/rotateDuration;isRotating = true;public void RotateTo(float _angleRange, int _axis, float _duration, float _accelerateDuration)isRotating = false;rotateType = CTRotationType.AccelerateUniformly;/RotateT

7、ype = 1;rotateAcceleration = 1/(rotateDuration - accelerateDuration)*accelerateDuration);initRotateArgument(_angleRange, _axis, _duration);switch(rotateAxis)case 0: /rotate around X axisrotateVector = Vector3.right;break;case 1:/rotate around Y axisrotateVector = Vector3.up;break;case 2:/rotate arou

8、nd Z axisrotateVector = Vector3.forward;break;default:break;accelerateDuration = _accelerateDuration;/ deltaRotate = angleRange/(_duration - _accelerateDuration*2);isRotating = true;void executeRotate()switch (rotateType)/case 0:/CTMoveType.Uniform:case CTRotationType.Uniform:uniformRotate();break;/

9、case 1:/CTMoveType.AccelerateUniformly:case CTRotationType.AccelerateUniformly:accelerateRotate();break;leftDuration -= Time.deltaTime;/* if (leftDuration (rotateDuration - accelerateDuration)rotateVelocity = (float)(angleRange*(rotateDuration - leftDuration)*rotateAcceleration);/ transform.Rotate(r

10、otateVelocity * Time.deltaTime*rotateVector, Space.World);transform.Rotate(rotateVelocity * rotateVector*Time.deltaTime, Space.World);else if (leftDuration accelerateDuration)rotateVelocity = (float)(angleRange*accelerateDuration)*rotateAcceleration);transform.Rotate(rotateVelocity*rotateVector*Time

11、.deltaTime, Space.World);else if (leftDuration 0)rotateVelocity= (float)(angleRange*leftDuration)*rotateAcceleration);transform.Rotate(rotateVelocity*rotateVector*Time.deltaTime, Space.World);elseisRotating = false;private void uniformRotate()print(leftDuration);/if(leftDuration)if(leftDuration 0)transform.Rotate(rotateVector*deltaRotate*Time.deltaTime, Space.World);/ unity3d 教程手册 * Time.deltaTime*deltaRotate, Space.World);elseisRotating = false;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报