using UnityEngine;
using System.Collections;
public class SwanTest01 : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//transform.Translate(-0.1f,0,0);
rigidbody2D.velocity = new Vector2(-10.0f, 0);
}
}
transform.Translate와 rigidbody2D.velocity를 이용한 움직임을 번갈아 가면서 테스트
고려 사항 : 어떤 컴퓨터는 CPU 성능이 뛰어나서 Update() 함수를 상대적으로 많이 호출될 수 있다. 즉, Translate()함수를 Time.deltaTime으로 조정하지 않고 사용하면 성능이 좋은 컴퓨터에서는 swan이 빠르게 움직일 것이다. 그러나, rigidbody2D.velocity는 시간에 비례하여 움직이기 때문에 이런 문제를 야기하지는 않는다.
using UnityEngine;
using System.Collections;
public class SwanTest02 : MonoBehaviour {
public float speed = -10.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(speed*Time.deltaTime,0,0);
//rigidbody2D.velocity = new Vector2(-10.0f, 0);
}
}
Translate()함수를 사용할 경우 Time.deltaTime을 이용하여 일정한 속도로 움직이게 할 수 있다.