用unity来写小球转向后向目标移动 +c#脚本
来源:互联网 发布:在阿里申请域名和 编辑:程序博客网 时间:2024/06/06 10:42
1.创建场景:
如图所示,在场景中加载一个cube、sphere、plane,
2.写脚本:主要脚本加在cube上,
主要本如下:
public class Move : MonoBehaviour {public Transform bbb; public float t=0;public Quaternion aaa;void Update ()
{mouseClick ();//cubeRotate ();cubeYidong (); }
void mouseClick(){if (Input.GetMouseButtonDown (0)){Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);RaycastHit hit;if (Physics.Raycast(ray,out hit)){if(hit.collider.gameObject.name=="Plane"){t=0;aaa = this.transform.rotation;bbb.position=new Vector3(hit.point.x,this.gameObject.transform.position.y,hit.point.z);}}}}
void cubeRotate(){t += Time.deltaTime;this.transform.rotation = Quaternion.Slerp (aaa,Quaternion.LookRotation(bbb.position-this.transform.position),t);}
void cubeYidong (){if (Quaternion.Angle(this.transform.rotation,Quaternion.LookRotation (bbb.position-this.transform.position))<0.05f) {this.transform.position = Vector3.Lerp(this.transform.position,bbb.position,Time.deltaTime);} }}
0 0
- 用unity来写小球转向后向目标移动 +c#脚本
- Unity摄像机 向指定位置移动旋转 C#脚本
- Unity脚本,平滑跟随目标物体移动和旋转
- Unity的安卓上的移动C#脚本
- unity。。。完美简单解决靠鼠标在屏幕上的移动来控制相机水平,垂直旋转的c#脚本
- unity 第三人称控制对象平移转向C#脚本(亲测有效)
- 用shell来写脚本
- 用shell来写脚本
- 写一个脚本来移动RMAN备件文件的位置。
- 【Unity】 相机移动脚本
- Unity中以一定的角速度转向目标
- 塔防TDTK 敌人移动到目标转向
- unity 实现键盘控制物体移动和转向
- Unity 3D 泰课网小球移动 相机跟随
- unity C#脚本规则
- Unity 中的C#脚本
- Unity C# 脚本教程
- Unity 中的C#脚本
- 第六周程序阅读(1)
- android消息推送 .
- ASP.NET和Javascript的Json数据交互
- 求两个整型变量的最大公约数
- 一元运算符 + 表示正号 - 表示负号
- 用unity来写小球转向后向目标移动 +c#脚本
- NoSQL数据库之Redis数据库管理三(list类型)
- 衍射极限、MTF与相机分辨率(1)
- strrchr函数的实现
- mllib:Exception in thread "main" org.apache.spark.SparkException: Input validation failed.
- UINavigationController使用详解
- android书架效果 .
- 只保留一个对象空间——静态方法调用私有构造方法
- 判断奇偶交替