Unity3D
Linear Translation
일등하이
2015. 8. 27. 20:11
반응형
http://answers.unity3d.com/questions/339561/linear-translation.html
using UnityEngine;
using System.Collections;
public class FollowPath : MonoBehaviour {
public GameObject follower;
public Transform[] pathNodes;
public float movementSpeed = 0.5f;
public bool continuouslyLoop = false;
private float pathPosition = 0f;
private int curNode = 0;
// Use this for initialization
void Start () {
if (follower == null) {
follower = this.gameObject;
}
}
// Update is called once per frame
void Update () {
if (pathNodes != null)
{
pathPosition += Time.deltaTime * movementSpeed;
if (pathPosition > 1f)
{
if (pathNodes.Length > curNode+2)
{
pathPosition = 0f;
curNode += 1;
}
else
{
if (continuouslyLoop)
{
pathPosition = 0f;
curNode = 0;
}
}
}
follower.transform.position = Vector3.Lerp( pathNodes[curNode].position, pathNodes[curNode+1].position, pathPosition );
}
}
}
반응형