1. DOMove
transform.DOMove(Vector3 targetPosition, float duration);
targetPosition: 이동할 위치
duration: 이동하는 데 걸리는 시간(초)
using UnityEngine;
using DG.Tweening;
public class MoveExample : MonoBehaviour
{
void Start()
{
// 2초 동안 (3, 0, 0) 위치로 이동
transform.DOMove(new Vector3(3, 0, 0), 2f);
}
}
2. DOScale
transform.DOScale(Vector3 targetScale, float duration);
targetScale: 최종 크기 (x, y, z)
duration: 변화하는 데 걸리는 시간(초)
using UnityEngine;
using DG.Tweening;
public class ScaleExample : MonoBehaviour
{
void Start()
{
// 1초 동안 크기를 2배(2, 2, 2)로 키움
transform.DOScale(new Vector3(2, 2, 2), 1f);
}
}
3. DORotate
transform.DORotate(Vector3 targetEulerAngles, float duration);
targetEulerAngles: 목표 회전 각도 (x, y, z, 단위는 도(degree))
duration: 회전하는 데 걸리는 시간(초)
using UnityEngine;
using DG.Tweening;
public class RotateExample : MonoBehaviour
{
void Start()
{
// 1초 동안 z축으로 90도 회전
transform.DORotate(new Vector3(0, 0, 90), 1f);
}
}
4. SetLoops
tween.SetLoops(int loops, LoopType type = LoopType.Restart);
loops: 반복 횟수 (예: 3번 반복)
LoopType: 반복 방식
Restart: 처음 위치로 돌아가서 반복
using UnityEngine;
using DG.Tweening;
public class LoopExample : MonoBehaviour
{
void Start()
{
// 오른쪽으로 2초 동안 3번 이동 (처음으로 돌아가면서 반복)
transform.DOMoveX(3f, 2f).SetLoops(3, LoopType.Restart);
}
}
Yoyo: 왕복 (앞뒤로 왔다 갔다)
using UnityEngine;
using DG.Tweening;
public class LoopExample : MonoBehaviour
{
void Start()
{
//2번 왕복, 움직임은 4번
transform.DOMoveX(2f, 1f).SetLoops(4, LoopType.Yoyo);
}
}
Incremental: 매 반복마다 값을 누적
SetRelative(): 상대적인 이동 거리
using UnityEngine;
using DG.Tweening;
public class DOTweenTest : MonoBehaviour
{
void Start()
{
transform.DOMoveX(1f, 1f)
.SetRelative() // 이동이 완료된 위치에서 재시작
.SetLoops(3, LoopType.Incremental)
.OnStepComplete(() =>
{
float X = transform.position.x;
Debug.Log("움직임 한 번 완료 = " + X);
});
}
}
- 1회차: x += 1 → x = 1
- 2회차: x += 1 → x = 2
- 3회차: x += 1 → x = 3
👉 총 3번 반복하며 누적 이동
Incremental: 매 반복마다 값을 누적
using UnityEngine;
using DG.Tweening;
public class DOTweenTest : MonoBehaviour
{
void Start()
{
transform.DOMoveX(1f, 0.5f)
.SetLoops(3, LoopType.Incremental)
.OnStepComplete(() =>
{
float X = transform.position.x;
Debug.Log("움직임 한 번 완료 = " + X);
});
}
}
시작 좌표에서 이동한 거리만큼 누적 이동한다.
0에서 시작해서 1로 갔으면
- 1회차: 0 += 1 → x = 1
- 2회차: 1 += 1 → x = 2
- 3회차: 2 += 1 → x = 3
2에서 시작해서 1로 갔으면
- 1회차: 2 += -1 → x = 1
- 2회차: 1 += -1 → x = 0
- 3회차: 0 += -1 → x = -1
'DOTWeen' 카테고리의 다른 글
DOTWeen: Ease4 Flash (0) | 2025.07.20 |
---|---|
DOTWeen: Ease3 탄성 (0) | 2025.07.20 |
DOTWeen: Ease2 함수 사용 (0) | 2025.07.19 |
DOTWeen: Ease1 (0) | 2025.07.19 |
DOTween: Sequence (0) | 2025.07.19 |