不做分享使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
/// <summary> /// Stone state. /// 砸石动画 /// </summary> using UnityEngine; using System.Collections; public class StoneState : MonoBehaviour { // 移动的开始轴向和结束轴向 public float beginX; public float endX; public float beginY; public float endY; // 确定移动的方向 下、右、上、左 public bool moveDirectionDown; public bool moveDirectionRight; public bool moveDirectionUp; public bool moveDirectionLeft; // 移动速度 float speed; // 移动最大速度 public float maxSpeed = 3; // 移动最小速度 public float minSpeed = -3; // 开始时间 public float beginTime = 0f; // 是否开始执行 bool isBegin = false; void Start () { speed = maxSpeed; // 0秒后开始执行BeginMove方法 Invoke ("BeginMove", beginTime); } void BeginMove (){ isBegin = true; } // Update is called once per frame void Update () { // 开始按照移动的方向执行 if (isBegin){ if (moveDirectionDown) MoveDown (); else if (moveDirectionRight) MoveRight (); else if (moveDirectionUp) MoveUp (); else if (moveDirectionLeft) MoveLeft (); } } void MoveLeft (){ // 通过判断实现位置循环执行 if (transform.localPosition.x < beginX) { speed = minSpeed; } if (transform.localPosition.x > endX){ speed = maxSpeed; } // 当位置小0.2时 则比例大0.16 实现顶点位置不变 拉伸物体 transform.localPosition = new Vector2 (transform.localPosition.x - 0.2f * Time.deltaTime * speed, transform.localPosition.y); transform.localScale = new Vector2 (transform.localScale.x + 0.16f * Time.deltaTime * speed, transform.localScale.y ); } void MoveRight (){ // 通过判断实现位置循环执行 if (transform.localPosition.x < beginX) { speed = maxSpeed; } if (transform.localPosition.x > endX){ speed = minSpeed; } // 当位置大0.2时 则比例大0.16 实现顶点位置不变 拉伸物体 transform.localPosition = new Vector2 (transform.localPosition.x + 0.2f * Time.deltaTime * speed, transform.localPosition.y); transform.localScale = new Vector2 (transform.localScale.x + 0.16f * Time.deltaTime * speed, transform.localScale.y); } void MoveDown (){ // 通过判断实现位置循环执行 if (transform.localPosition.y < beginY) { speed = minSpeed; } if (transform.localPosition.y > endY){ speed = maxSpeed; } // 当位置小0.2时 则比例大0.16 实现顶点位置不变 拉伸物体 transform.localPosition = new Vector2 (transform.localPosition.x, transform.localPosition.y - 0.2f * Time.deltaTime * speed); transform.localScale = new Vector2 (transform.localScale.x, transform.localScale.y + 0.16f * Time.deltaTime * speed); } void MoveUp (){ // 通过判断实现位置循环执行 if (transform.localPosition.y < beginY) { speed = minSpeed; } if (transform.localPosition.y > endY){ speed = maxSpeed; } // 当位置大0.2时 则比例大0.16 实现顶点位置不变 拉伸物体 transform.localPosition = new Vector2 (transform.localPosition.x, transform.localPosition.y + 0.2f * Time.deltaTime * speed); transform.localScale = new Vector2 (transform.localScale.x, transform.localScale.y + 0.16f * Time.deltaTime * speed); } } |
- 本文固定链接: http://www.u3d8.com/?p=176
- 转载请注明: 网虫虫 在 u3d8.com 发表过