Compare commits
2 Commits
4257cec1ec
...
430fb9205b
Author | SHA1 | Date | |
---|---|---|---|
430fb9205b | |||
30ad98fd9b |
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,9 @@ public class PlayerMove : MonoBehaviour
|
||||
public float duration = 5f; // 移动的持续时间
|
||||
public bool isLooping = false; // 是否循环路径
|
||||
int startIndex = 0;
|
||||
int endIndex = 0;
|
||||
int endIndex = 0;
|
||||
|
||||
public float Speed = 2.5f;
|
||||
public Transform EndPos;
|
||||
|
||||
public Transform TypeEndPos1;
|
||||
@ -20,6 +22,7 @@ public class PlayerMove : MonoBehaviour
|
||||
public Transform TypeEndPos5;
|
||||
public Transform TypeEndPos6;
|
||||
|
||||
public Transform JumpPos;
|
||||
private void Start()
|
||||
{
|
||||
|
||||
@ -38,6 +41,15 @@ public class PlayerMove : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool JudagePos1()
|
||||
{
|
||||
if (EndPos==TypeEndPos1)
|
||||
{
|
||||
return true ;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void StartMove()
|
||||
{
|
||||
|
||||
@ -50,25 +62,56 @@ public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
startIndex = i;
|
||||
Debug.Log("Startindex"+i);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (EndPos == pathPoints[i])
|
||||
{
|
||||
endIndex = i;
|
||||
Debug.Log("Endindex" + i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
OnMove(waypoints);
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
OnMove(waypoints);
|
||||
}
|
||||
|
||||
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("数组起始点" + waypoints[0]);
|
||||
// 使用 DoTween 的 DOPath 方法创建路径动画
|
||||
Tween pathTween = objectToMove.DOPath(waypoints, duration, PathType.Linear)
|
||||
.SetEase(Ease.Linear) // 线性过渡效果
|
||||
.SetLoops(isLooping ? -1 : 0)
|
||||
.OnComplete(AfterMove);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -77,5 +120,17 @@ public class PlayerMove : MonoBehaviour
|
||||
|
||||
PlayerMovePos.instance.StartPos =EndPos;
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd2c97d0d9336ee4a92b974253ed6842
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user