Update
Update는 MonoBehaviour 클래스가 제공하는 함수입니다. MonoBehaviour 클래스는 Update(), FixedUpdate(), LateUpdate() 총 3가지의 함수를 제공합니다. Update에 대해 자세히 알아보겠습니다.
Update()
Update()는 매 프레임마다 호출되는 함수입니다. 컴퓨터의 성능에 따라 Update()가 호출되는 횟수는 다를 수 있으며 호출되는 간격 또한 일정하지 않습니다. Update()는 가장 많이 사용되는 함수로 주로 시간에 따른 동작 구현이나, 키보드 입력 확인, 지속적인 상태 체크 등을 할때 사용됩니다.
using UnityEngine; | |
public class UpdateExample : MonoBehaviour | |
{ | |
void Update() | |
{ | |
Debug.Log("Update() : " + Time.deltaTime); | |
} | |
} |

FixedUpdate()
FixedUpdate()는 고정 프레임마다 호출되는 함수입니다. FixedUpdate()가 호출되는 간격은 일정합니다. 호출되는 간격이 일정하기 때문에 FixedUpdate()는 물리 기능을 사용할 때 주로 사용됩니다. 예를 들어 Rigidbody의 속도나, 힘을 가하는 경우 FixedUpdate()에서 처리해야 합니다.
using UnityEngine; | |
public class FixedUpdateExample : MonoBehaviour | |
{ | |
void FixedUpdate() | |
{ | |
Debug.Log("FixedUpdate() : " + Time.deltaTime); | |
} | |
} |

LateUpdate()
LateUpdate()는 모든 Update함수( Update(), FixedUpdate() )가 호출되고 난 후 호출되는 함수입니다. Update()와 마찬가지로 매 프레임마다 호출됩니다. LateUpdate()는 모든 Update 함수가 호출되고 난 후에 특정 기능을 해야할 때 주로 사용됩니다. 예를 들어 카메라가 캐릭터를 따라다녀야 할 경우 캐릭터의 이동이 끝난 뒤에 카메라의 이동을 LateUpdate()에서 처리합니다.
using UnityEngine; | |
public class LateUpdateExample : MonoBehaviour | |
{ | |
void LateUpdate() | |
{ | |
Debug.Log("LateUpdate() : " + Time.deltaTime); | |
} | |
} |

※ Time.deltaTime : 현재 프레임과 이전 프레임 사이의 시간
참고
Unity - Scripting API: MonoBehaviour.Update()
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho
docs.unity3d.com
Unity - Scripting API: MonoBehaviour.FixedUpdate()
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho
docs.unity3d.com
Unity - Scripting API: MonoBehaviour.LateUpdate()
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho
docs.unity3d.com
댓글