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

@ -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);
}
}

View File

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