'docolor'에 해당되는 글 1건

  1. 2020.05.10 DOTween: DOMove(), DOColor() simple example - DOTween 간단한 예제
반응형

DOTween의 DOMove(), DOColor() 예제


아래와 같은 스크립트를 만든다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
 
public class Tween : MonoBehaviour
{
    public Ease ease;
 
    // Start is called before the first frame update
    void Start()
    {
        // static DOTween.Init(bool recycleAllByDefault = false, bool useSafeMode = true, LogBehaviour logBehaviour = LogBehaviour.ErrorsOnly)
        // Initializes DOTween.
        DOTween.Init(falsetrue, LogBehaviour.ErrorsOnly);
 
        // DOMove(Vector3 to, float duration, bool snapping)
        // Moves the target's position to the given value.
        transform.DOMove(new Vector3(0.0f, 0.0f, 5.0f), 3.0f, false).SetEase(ease).SetLoops(-1, LoopType.Yoyo);
 
        // DOColor(Color to, float duration)
        // Changes the target's color to the given one.
        transform.GetComponent<MeshRenderer>().material.DOColor(Color.red, 3.0f).SetLoops(-1, LoopType.Yoyo);
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
}
 


스크립트 이름은 Tween으로 지정 한다.


Cube를 생성하고 Tween 스크립트를 추가한다.


Inspector 창의 Tween 스크립트에서 Ease 변수를 In Bounce 등 원하는 ease로 변경한다.


플레이 버튼을 클릭 하면 Cube가 지정한 동작으로 움직이며 색깔이 변경 된다.

반응형
Posted by J-sean
: