add ckg
plantilla base para movimiento básico
This commit is contained in:
57
Assets/Game Kit Controller/Scripts/Others/SplineWalker.cs
Normal file
57
Assets/Game Kit Controller/Scripts/Others/SplineWalker.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SplineWalker : MonoBehaviour
|
||||
{
|
||||
public enum SplineWalkerMode
|
||||
{
|
||||
Once,
|
||||
Loop,
|
||||
PingPong
|
||||
}
|
||||
|
||||
public BezierSpline spline;
|
||||
|
||||
public float duration;
|
||||
|
||||
public bool lookForward;
|
||||
|
||||
public SplineWalkerMode mode;
|
||||
|
||||
public float progress;
|
||||
public bool goingForward = true;
|
||||
|
||||
private void Update ()
|
||||
{
|
||||
if (goingForward) {
|
||||
progress += Time.deltaTime / duration;
|
||||
|
||||
if (progress > 1f) {
|
||||
if (mode == SplineWalkerMode.Once) {
|
||||
progress = 1f;
|
||||
} else if (mode == SplineWalkerMode.Loop) {
|
||||
progress -= 1f;
|
||||
} else {
|
||||
progress = 2f - progress;
|
||||
|
||||
goingForward = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
progress -= Time.deltaTime / duration;
|
||||
|
||||
if (progress < 0f) {
|
||||
progress = -progress;
|
||||
|
||||
goingForward = true;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 position = spline.GetPoint (progress);
|
||||
|
||||
transform.localPosition = position;
|
||||
|
||||
if (lookForward) {
|
||||
transform.LookAt (position + spline.GetDirection (progress));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user