Escape From The Earth 逃离地球
1、对Tags进行管理
设置一个全局的类,类似如下:
public class Tags:MonoBehaviour{ public const string player="Player"; }
调用Tags.player
2、发送消息
unity中每一个对象都有SendMessage,BroadcastMessage,SendMessageUpwards 三个发送消息的方法!
具体使用方法参考:http://www.cnblogs.com/MrZivChu/p/sendmessage.html
3、利用iTween绘制路径线
public Transform[] points; public void OnDrawGizmos() { iTween.DrawPath(points); }
4、人物移动
public float moveSpeed = 100; public Vector3 targetPosition; void Update() {
//获得人物前进方向 Vec tor3 moveDir = targetPosition - transform.position; transform.positon += moveDir.normalized * moveSpeed * Time.deltaTime; }
5、获得障碍物生成的点
因为地形是不平整的,有高低起伏的,所以我们的障碍物生成点是根据比率来算的
Vector3.Lerp(prePoint,nextPoint,(z-prePoint.z) / (nextPoint.z - prePoint.z)) // Lerp会根据第三个参数(比率)来算出上一个点和下一个点之间的一个点
6、动画队列
animation.Play("Idle1"); animation.PlayQueued("Idle2");//把Idle2动画加入队列,也就是说,当Idle1播放完,就去播放Idle2的动画
7、获得触摸方向(鼠标)
public enum TouchDir { None, Left, Right, Top, Bottom } Vector3 lastMouseDown = Vector3.zero; TouchDir GetTouchDir() { if (Input.GetMouseButton(0)) { lastMouseDown = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { Vector3 mouseUp = Input.mousePosition; Vector3 touchOffset = mouseUp - lastMouseDown; if (Mathf.Abs(touchOffset.x) > 50 || Mathf.Abs(touchOffset.y) > 50) { if (Mathf.Abs(touchOffset.x) > Mathf.Abs(touchOffset.y) && touchOffset.x > 0) { return TouchDir.Right; } else if (Mathf.Abs(touchOffset.x) > Mathf.Abs(touchOffset.y) && touchOffset.x < 0) { return TouchDir.Left; } else if (Mathf.Abs(touchOffset.x) < Mathf.Abs(touchOffset.y) && touchOffset.y > 0) { return TouchDir.Top; } else if (Mathf.Abs(touchOffset.x) < Mathf.Abs(touchOffset.y) && touchOffset.y < 0) { return TouchDir.Bottom; } } } return TouchDir.None; }
8、根据动画时长计时完成动画播放
bool slide = true; float allTime = 1.73f;//此动画总共时间为1.73s float initTime = 0; void LateUpdate() { if (slide) { initTime += Time.deltaTime; if (initTime > allTime) { initTime = 0; slide = false; } animation.Play("slide"); } }
9、人物跳跃
转载于:https://www.cnblogs.com/MrZivChu/p/EscapeFromTheEarth.html