Linear Translation
Unity3D 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 );
}
}
}
반응형
'Unity3D' 카테고리의 다른 글
Text 한글자씩 나오게 하는 방법. (0) | 2015.08.31 |
---|---|
NGUI position to World position (0) | 2015.08.27 |
타일맵 생성 ( isometric ) (0) | 2015.08.26 |
astar_test 5 (0) | 2015.08.24 |
astar test 4 (0) | 2015.08.24 |