using System.Collections.Generic; using System.Threading; using Cysharp.Threading.Tasks; using DG.Tweening; using Game.Pathfinding; using Sirenix.OdinInspector; using UnityEngine; namespace Game.Player; class PlayerInfo : MonoBehaviour { [SerializeField] [ReadOnly] private IPlayer _player; [SerializeField] private float speed = 1f; public void SetPlayer(IPlayer player) { this._player = player; this.gameObject.name = this._player.playerName; } public async UniTask MoveAsync(List wayPoint, Vector2 endPos, CancellationToken token) { // enter this room foreach (var point in wayPoint) { await Move(point.position, token); } // enter room a point await Move(endPos, token); return true; } async UniTask Move(Vector2 endPos, CancellationToken token) { var distance = Vector3.Distance(this.transform.position, endPos); var time = distance / this.speed; // bool isMoveing = true; // while (isMoveing) // { // await UniTask.Yield(token); // if (Vector3.Distance(transform.position, endPos) <= 0.1f) // { // isMoveing = false; // break; // } // // transform.DOMove(endPos, time); // } transform.DOMove(endPos, time); float delayTimeSpan = time * 1000; await UniTask.Delay((int)delayTimeSpan); } }