_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/PlayerMove.cs

81 lines
2.0 KiB
C#
Raw Normal View History

2024-11-12 19:43:17 +08:00
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class PlayerMove : MonoBehaviour
{
public Transform objectToMove; // Ҫ<>ƶ<EFBFBD><C6B6>Ķ<EFBFBD><C4B6><EFBFBD>
public Transform[] pathPoints; // ·<><C2B7><EFBFBD>ϵĵ<CFB5><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float duration = 5f; // <20>ƶ<EFBFBD><C6B6>ij<EFBFBD><C4B3><EFBFBD>ʱ<EFBFBD><CAB1>
public bool isLooping = false; // <20>Ƿ<EFBFBD>ѭ<EFBFBD><D1AD>·<EFBFBD><C2B7>
int startIndex = 0;
int endIndex = 0;
public Transform EndPos;
public Transform TypeEndPos1;
public Transform TypeEndPos2;
public Transform TypeEndPos3;
public Transform TypeEndPos4;
public Transform TypeEndPos5;
public Transform TypeEndPos6;
private void Start()
{
}
public bool JudgeEnd(Transform pos)
{
if (pos==TypeEndPos1|| pos == TypeEndPos2 || pos == TypeEndPos3 || pos == TypeEndPos4 || pos == TypeEndPos5 || pos == TypeEndPos6 )
{
return true;
}
return false;
}
public void StartMove()
{
// <20><>ȡ·<C8A1><C2B7><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>λ<EFBFBD><CEBB>
for (int i = 0; i < pathPoints.Length; i++)
{
if (PlayerMovePos.instance.StartPos == pathPoints[i])
{
startIndex = i;
Debug.Log("Startindex"+i);
break;
}
}
Vector3[] waypoints = new Vector3[pathPoints.Length-startIndex];
for (int i=startIndex,j=0;j< pathPoints.Length&&i< pathPoints.Length; i++,j++)
{
waypoints[j]=pathPoints[i].position;
}
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>" + waypoints[0]);
// ʹ<><CAB9> DoTween <20><> DOPath <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Tween pathTween = objectToMove.DOPath(waypoints, duration, PathType.Linear)
.SetEase(Ease.Linear) // <20><><EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>Ч<EFBFBD><D0A7>
.SetLoops(isLooping ? -1 : 0)
.OnComplete(AfterMove);
}
public void AfterMove()
{
PlayerMovePos.instance.StartPos =EndPos;
Debug.Log("<22>޸<EFBFBD>StartPosֵ" + PlayerMovePos.instance.StartPos);
}
}