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;
|
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
public float Speed;
|
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-13 02:03:11 +08:00
|
|
|
|
|
|
|
|
|
public Transform Pos1Parent;
|
|
|
|
|
public Transform Pos2Parent;
|
|
|
|
|
public Transform Pos3Parent;
|
|
|
|
|
public Transform Pos4Parent;
|
|
|
|
|
public Transform Pos5Parent;
|
|
|
|
|
public Transform Pos6Parent;
|
|
|
|
|
|
|
|
|
|
public Transform OutParent;
|
|
|
|
|
|
|
|
|
|
public Transform ReturnPos;//<2F><><EFBFBD>ص<EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
|
|
|
|
public bool IsBoos;
|
|
|
|
|
|
2024-11-12 19:43:17 +08:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
2024-11-13 02:03:11 +08:00
|
|
|
|
Speed = 2f;
|
2024-11-12 19:43:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
public void MoveOutParent()
|
|
|
|
|
{
|
|
|
|
|
// <20><>¼ԭʼ<D4AD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><> childObject <20><>Ϊ<EFBFBD>µ<EFBFBD> parentObject <20><><EFBFBD>ӽڵ㣬<DAB5><E3A3AC><EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>λ<EFBFBD><CEBB>
|
|
|
|
|
objectToMove.SetParent(OutParent);
|
|
|
|
|
objectToMove.SetAsLastSibling();
|
2024-11-12 19:43:17 +08:00
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void MoveInParent(Transform Parent)
|
2024-11-12 19:43:17 +08:00
|
|
|
|
{
|
2024-11-13 02:03:11 +08:00
|
|
|
|
objectToMove.SetParent(Parent);
|
|
|
|
|
objectToMove.SetAsFirstSibling();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void JudgeEnd()
|
|
|
|
|
{
|
|
|
|
|
if (EndPos == TypeEndPos1)
|
2024-11-12 19:43:17 +08:00
|
|
|
|
{
|
2024-11-13 02:03:11 +08:00
|
|
|
|
MoveInParent(Pos1Parent);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.HouseId = 1;
|
|
|
|
|
}
|
2024-11-13 21:45:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.HouseId = 1;
|
|
|
|
|
}
|
2024-11-12 19:43:17 +08:00
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
else if (EndPos == TypeEndPos2)
|
|
|
|
|
{
|
2024-11-12 19:43:17 +08:00
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
MoveInParent(Pos2Parent);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.HouseId = 2;
|
|
|
|
|
}
|
2024-11-13 21:45:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.HouseId = 2;
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
else if(EndPos == TypeEndPos3)
|
|
|
|
|
{
|
|
|
|
|
MoveInParent(Pos3Parent);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.HouseId = 3;
|
|
|
|
|
}
|
2024-11-13 21:45:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.HouseId = 3;
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
else if (EndPos == TypeEndPos4)
|
|
|
|
|
{
|
|
|
|
|
MoveInParent(Pos4Parent);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.HouseId = 4;
|
|
|
|
|
}
|
2024-11-13 21:45:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.HouseId = 4;
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
else if (EndPos == TypeEndPos5)
|
|
|
|
|
{
|
|
|
|
|
MoveInParent(Pos5Parent);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.HouseId = 5;
|
|
|
|
|
}
|
2024-11-13 21:45:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.HouseId = 5;
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
else if (EndPos == TypeEndPos6)
|
|
|
|
|
{
|
|
|
|
|
MoveInParent(Pos6Parent);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.HouseId = 6;
|
|
|
|
|
}
|
2024-11-13 21:45:48 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.HouseId = 6;
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReturnStartPos()//<2F>ص<EFBFBD><D8B5><EFBFBD>ʼ<EFBFBD><CABC>
|
|
|
|
|
{
|
|
|
|
|
EndPos = ReturnPos;
|
|
|
|
|
StartMove();
|
2024-11-12 19:43:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
|
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++)
|
|
|
|
|
{
|
2024-11-13 02:03:11 +08:00
|
|
|
|
if (!IsBoos&&PlayerMovePos.instance.StartPos == pathPoints[i])
|
2024-11-12 19:43:17 +08:00
|
|
|
|
{
|
|
|
|
|
startIndex = i;
|
|
|
|
|
Debug.Log("Startindex"+i);
|
2024-11-13 02:03:11 +08:00
|
|
|
|
|
2024-11-12 21:53:49 +08:00
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
else if (IsBoos && BossContro.instance.BoosStartPos== 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()
|
|
|
|
|
{
|
2024-11-12 21:53:49 +08:00
|
|
|
|
|
2024-11-13 18:01:18 +08:00
|
|
|
|
|
|
|
|
|
if (!PlayerMovePos.instance.IsReturn)
|
2024-11-13 02:03:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
2024-11-13 18:01:18 +08:00
|
|
|
|
objectToMove.DOMoveY(objectToMove.position.y + 100, 0.5f).OnComplete(()=>{
|
|
|
|
|
JudgeEnd();
|
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.StartPos = EndPos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PlayerMovePos.instance.PlayAni.SetInteger("State",0);
|
|
|
|
|
MaskContro.instance.SetMask(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//BossContro.instance.BossAni.SetInteger("State", 0);//ֹͣ<CDA3>ƶ<EFBFBD>
|
|
|
|
|
StartCoroutine(BoosAttack());
|
|
|
|
|
BossContro.instance.BoosStartPos = EndPos;
|
|
|
|
|
|
|
|
|
|
//JudgeSuccOrFail();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-11-13 18:01:18 +08:00
|
|
|
|
PlayerMovePos.instance.IsReturn = false;//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
MaskContro.instance.SetMask(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-11-13 02:03:11 +08:00
|
|
|
|
|
|
|
|
|
|
2024-11-13 18:01:18 +08:00
|
|
|
|
IEnumerator BoosAttack()
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.BossAni.SetInteger("State", 2);
|
|
|
|
|
yield return new WaitForSeconds(3f);
|
|
|
|
|
BossContro.instance.BossAni.SetInteger("State", 0);
|
2024-11-13 21:45:48 +08:00
|
|
|
|
|
|
|
|
|
BettingBtn.instance.GiveMoney();
|
|
|
|
|
yield return new WaitForSeconds(2f);
|
2024-11-13 18:01:18 +08:00
|
|
|
|
JudgeSuccOrFail();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
|
2024-11-13 18:01:18 +08:00
|
|
|
|
public void JudgeSuccOrFail()
|
|
|
|
|
{
|
|
|
|
|
if (BossContro.instance.BoosStartPos == PlayerMovePos.instance.StartPos && PlayerMovePos.instance.HadChoise)
|
|
|
|
|
{
|
|
|
|
|
//BossContro.instance.BossAni.SetInteger("State", 2);//boos<6F><73><EFBFBD><EFBFBD>
|
|
|
|
|
Debug.Log("ʧ<><CAA7>");//ʧ<><CAA7>
|
|
|
|
|
FailPanel.instance.ShowPanel();
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
2024-11-13 18:01:18 +08:00
|
|
|
|
else if (BossContro.instance.BoosStartPos != PlayerMovePos.instance.StartPos && PlayerMovePos.instance.HadChoise)
|
2024-11-13 02:03:11 +08:00
|
|
|
|
{
|
2024-11-13 18:01:18 +08:00
|
|
|
|
Debug.Log("ʤ<><CAA4>");//ʤ<><CAA4>
|
|
|
|
|
SucceePanel.instance.ShowPanel();
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-11-13 18:01:18 +08:00
|
|
|
|
Debug.Log("û<><C3BB>ʧ<EFBFBD>ܺ<EFBFBD>ʤ<EFBFBD><CAA4>");//ʤ<><CAA4>
|
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
}
|
2024-11-13 18:01:18 +08:00
|
|
|
|
HegemonTime.instance.StartCoroutine(HegemonTime.instance.StartGame());//<2F><><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Rotate()
|
|
|
|
|
{
|
|
|
|
|
Vector3 currentRotation = objectToMove.localEulerAngles;
|
|
|
|
|
currentRotation.y += 180f;
|
|
|
|
|
objectToMove.localEulerAngles = currentRotation;
|
2024-11-12 21:53:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMove(Vector3[] waypoints)
|
|
|
|
|
{
|
2024-11-13 18:01:18 +08:00
|
|
|
|
if (!IsBoos)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.PlayAni.SetInteger("State", 1);
|
|
|
|
|
MaskContro.instance.SetMask(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 02:03:11 +08:00
|
|
|
|
MoveOutParent();
|
2024-11-12 21:53:49 +08:00
|
|
|
|
Tween pathTween = objectToMove.DOPath(waypoints, duration, PathType.Linear)
|
2024-11-13 18:01:18 +08:00
|
|
|
|
.SetEase(Ease.Linear) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><D4B9><EFBFBD>Ч<EFBFBD><D0A7>
|
|
|
|
|
.SetLoops(isLooping ? -1 : 0)
|
|
|
|
|
.OnWaypointChange((index) =>
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>嵽<EFBFBD><E5B5BD>ij<EFBFBD><C4B3>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ʱ<EFBFBD>ص<EFBFBD>
|
|
|
|
|
if (index < waypoints.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
Vector3 currentWaypoint = waypoints[index];
|
|
|
|
|
Vector3 nextWaypoint = waypoints[index + 1];
|
|
|
|
|
if (IsBoos)
|
|
|
|
|
{
|
|
|
|
|
if (nextWaypoint.x < currentWaypoint.x && !BossContro.instance.IsLeft)
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.IsLeft = true;
|
|
|
|
|
// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ࣨ<EFBFBD><E0A3A8>Y<EFBFBD><59><EFBFBD><EFBFBD>ת180<38>ȣ<EFBFBD>
|
|
|
|
|
Rotate();
|
|
|
|
|
}
|
|
|
|
|
else if (nextWaypoint.x > currentWaypoint.x && BossContro.instance.IsLeft)
|
|
|
|
|
{
|
|
|
|
|
BossContro.instance.IsLeft = false;
|
|
|
|
|
Rotate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA>ת
|
|
|
|
|
if (nextWaypoint.x < currentWaypoint.x && !PlayerMovePos.instance.IsLeft)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.IsLeft = true;
|
|
|
|
|
// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ࣨ<EFBFBD><E0A3A8>Y<EFBFBD><59><EFBFBD><EFBFBD>ת180<38>ȣ<EFBFBD>
|
|
|
|
|
Rotate();
|
|
|
|
|
}
|
|
|
|
|
else if (nextWaypoint.x > currentWaypoint.x && PlayerMovePos.instance.IsLeft)
|
|
|
|
|
{
|
|
|
|
|
PlayerMovePos.instance.IsLeft = false;
|
|
|
|
|
Rotate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.OnComplete(AfterMove);
|
2024-11-12 19:43:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|