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

136 lines
3.4 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;
2024-11-12 21:53:49 +08:00
int endIndex = 0;
public float Speed = 2.5f;
2024-11-12 19:43:17 +08:00
public Transform EndPos;
public Transform TypeEndPos1;
public Transform TypeEndPos2;
public Transform TypeEndPos3;
public Transform TypeEndPos4;
public Transform TypeEndPos5;
public Transform TypeEndPos6;
2024-11-12 21:53:49 +08:00
public Transform JumpPos;
2024-11-12 19:43:17 +08:00
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;
}
2024-11-12 21:53:49 +08:00
public bool JudagePos1()
{
if (EndPos==TypeEndPos1)
{
return true ;
}
return false;
}
2024-11-12 19:43:17 +08:00
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);
2024-11-12 21:53:49 +08:00
}
if (EndPos == pathPoints[i])
{
endIndex = i;
Debug.Log("Endindex" + i);
2024-11-12 19:43:17 +08:00
}
}
2024-11-12 21:53:49 +08:00
2024-11-12 19:43:17 +08:00
2024-11-12 21:53:49 +08:00
if (endIndex>startIndex)
2024-11-12 19:43:17 +08:00
{
2024-11-12 21:53:49 +08:00
duration=(endIndex-startIndex)/Speed;
Vector3[] waypoints = new Vector3[endIndex-startIndex+1];
for (int i=startIndex,j=0;j< pathPoints.Length&&i<=endIndex; i++,j++)
{
if (!JudagePos1() && pathPoints[i]==JumpPos)
{
waypoints[j] = pathPoints[i - 1].position;
continue;
}
waypoints[j]=pathPoints[i].position;
2024-11-12 19:43:17 +08:00
2024-11-12 21:53:49 +08:00
}
OnMove(waypoints);
2024-11-12 19:43:17 +08:00
}
2024-11-12 21:53:49 +08:00
else if(endIndex < startIndex)
{
duration = (startIndex-endIndex) / Speed;
Vector3[] waypoints = new Vector3[startIndex-endIndex + 1];
for (int i = startIndex, j = 0; j < pathPoints.Length && i >= endIndex; i--, j++)
{
if (!JudagePos1() && pathPoints[i] == JumpPos)
{
waypoints[j] = pathPoints[i+1].position;
continue;
}
waypoints[j] = pathPoints[i].position;
2024-11-12 19:43:17 +08:00
2024-11-12 21:53:49 +08:00
}
OnMove(waypoints);
}
2024-11-12 19:43:17 +08:00
}
public void AfterMove()
{
PlayerMovePos.instance.StartPos =EndPos;
Debug.Log("<22>޸<EFBFBD>StartPosֵ" + PlayerMovePos.instance.StartPos);
2024-11-12 21:53:49 +08:00
objectToMove.DOMoveY(objectToMove.position.y+100,0.5f);
}
public void OnMove(Vector3[] waypoints)
{
// ʹ<><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);
2024-11-12 19:43:17 +08:00
}
}