Compare commits

...

2 Commits

Author SHA1 Message Date
GL
430fb9205b add 2024-11-12 22:02:08 +08:00
GL
30ad98fd9b add 2024-11-12 21:53:49 +08:00
3 changed files with 944 additions and 1049 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@ public class PlayerMove : MonoBehaviour
public bool isLooping = false; // ÊÇ·ñÑ­»·Â·¾¶ public bool isLooping = false; // ÊÇ·ñÑ­»·Â·¾¶
int startIndex = 0; int startIndex = 0;
int endIndex = 0; int endIndex = 0;
public float Speed = 2.5f;
public Transform EndPos; public Transform EndPos;
public Transform TypeEndPos1; public Transform TypeEndPos1;
@ -20,6 +22,7 @@ public class PlayerMove : MonoBehaviour
public Transform TypeEndPos5; public Transform TypeEndPos5;
public Transform TypeEndPos6; public Transform TypeEndPos6;
public Transform JumpPos;
private void Start() private void Start()
{ {
@ -38,6 +41,15 @@ public class PlayerMove : MonoBehaviour
return false; return false;
} }
public bool JudagePos1()
{
if (EndPos==TypeEndPos1)
{
return true ;
}
return false;
}
public void StartMove() public void StartMove()
{ {
@ -50,24 +62,55 @@ public class PlayerMove : MonoBehaviour
{ {
startIndex = i; startIndex = i;
Debug.Log("Startindex"+i); Debug.Log("Startindex"+i);
break;
}
if (EndPos == pathPoints[i])
{
endIndex = i;
Debug.Log("Endindex" + i);
} }
} }
Vector3[] waypoints = new Vector3[pathPoints.Length-startIndex];
for (int i=startIndex,j=0;j< pathPoints.Length&&i< pathPoints.Length; i++,j++)
if (endIndex>startIndex)
{ {
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; }
waypoints[j]=pathPoints[i].position;
}
OnMove(waypoints);
} }
Debug.Log("数组起始点" + waypoints[0]); else if(endIndex < startIndex)
// 使用 DoTween 的 DOPath 方法创建路径动画 {
Tween pathTween = objectToMove.DOPath(waypoints, duration, PathType.Linear) duration = (startIndex-endIndex) / Speed;
.SetEase(Ease.Linear) // 线性过渡效果 Vector3[] waypoints = new Vector3[startIndex-endIndex + 1];
.SetLoops(isLooping ? -1 : 0) for (int i = startIndex, j = 0; j < pathPoints.Length && i >= endIndex; i--, j++)
.OnComplete(AfterMove); {
if (!JudagePos1() && pathPoints[i] == JumpPos)
{
waypoints[j] = pathPoints[i+1].position;
continue;
}
waypoints[j] = pathPoints[i].position;
}
OnMove(waypoints);
}
} }
@ -77,5 +120,17 @@ public class PlayerMove : MonoBehaviour
PlayerMovePos.instance.StartPos =EndPos; PlayerMovePos.instance.StartPos =EndPos;
Debug.Log("ÐÞ¸ÄStartPosÖµ" + PlayerMovePos.instance.StartPos); Debug.Log("ÐÞ¸ÄStartPosÖµ" + PlayerMovePos.instance.StartPos);
objectToMove.DOMoveY(objectToMove.position.y+100,0.5f);
}
public void OnMove(Vector3[] waypoints)
{
// 使用 DoTween 的 DOPath 方法创建路径动画
Tween pathTween = objectToMove.DOPath(waypoints, duration, PathType.Linear)
.SetEase(Ease.Linear) // 线性过渡效果
.SetLoops(isLooping ? -1 : 0)
.OnComplete(AfterMove);
} }
} }

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: fd2c97d0d9336ee4a92b974253ed6842
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: