.81640625using UnityEngine;
using System.Collections;
public class TestCoroutine : MonoBehaviour {
public float moveSpeed = 1;
public Vector3[] path;
// Use this for initialization
void Start () {
//StartCoroutine(MoveToPosition(new Vector3(3, 0, 0)));
StartCoroutine(MoveOnPath(true));
}
IEnumerator MoveCube1(){
transform.Translate(2, 0, 0);
yield return new WaitForSeconds(1.0f);
transform.Translate(0, 2, 0);
yield return new WaitForSeconds(2.0f);
transform.Translate(2, 2, 0);
yield return new WaitForSeconds(3.0f);
}
IEnumerator MoveCube2(){
int count = 3;
while(Time.time < 2 && count > 0){
yield return new WaitForSeconds(0.01f);
transform.Translate(2f, 0, 0);
count -= 1;
}
}
IEnumerator MoveCube3(){
while(Time.time < 3)
{
transform.Translate(0.05f, 0, 0);
yield return 0;
}
}
IEnumerator MoveToPosition(Vector3 target)
{
while((transform.position - target).sqrMagnitude > 0.01f)
{
transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime);
yield return 0;
}
}
IEnumerator MoveOnPath(bool loop)
{
foreach(Vector3 point in path)
yield return StartCoroutine(MoveToPosition(point));
}
// Update is called once per frame
void Update () {
}
}
'Computer Language > 유니티' 카테고리의 다른 글
파티클 1번과 2번 2번을 주로 애용 (0) | 2014.07.21 |
---|---|
ITWEEN PATH탐지. 쉐이크, 좌우이동 (0) | 2014.07.01 |
하스스톤 디딤돌 (0) | 2014.07.01 |
SkinnedMeshRenderer (0) | 2014.06.27 |
GUI 씬 전환 (0) | 2014.06.23 |