12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using UnityEngine;
- namespace Pathfinding.Examples {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_mine_bot_animation.php")]
- public class MineBotAnimation : VersionedMonoBehaviour {
-
-
-
-
- public Animator anim;
-
-
-
-
- public GameObject endOfPathEffect;
- bool isAtDestination;
- IAstarAI ai;
- Transform tr;
- protected override void Awake () {
- base.Awake();
- ai = GetComponent<IAstarAI>();
- tr = GetComponent<Transform>();
- }
-
- protected Vector3 lastTarget;
-
-
-
-
-
-
- void OnTargetReached () {
- if (endOfPathEffect != null && Vector3.Distance(tr.position, lastTarget) > 1) {
- GameObject.Instantiate(endOfPathEffect, tr.position, tr.rotation);
- lastTarget = tr.position;
- }
- }
- protected void Update () {
- if (ai.reachedEndOfPath) {
- if (!isAtDestination) OnTargetReached();
- isAtDestination = true;
- } else isAtDestination = false;
-
- Vector3 relVelocity = tr.InverseTransformDirection(ai.velocity);
- relVelocity.y = 0;
-
- anim.SetFloat("NormalizedSpeed", relVelocity.magnitude / anim.transform.lossyScale.x);
- }
- }
- }
|