unity3d外掛之 DoTween

zsdeus133發表於2018-03-15

勝利介面

有時候直接用transform.Doxxxx會重複播放,這時候就可以用Tweener來控制

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class TestDotween : MonoBehaviour {

    public Vector3 vec3;

    Tweener myTweener;
    // Use this for initialization
    void Start () {
        // "砰" 效果
        myTweener = transform.DOPunchScale(new Vector3(1.3f, 1.3f, 0), 1f);
        myTweener.Pause();
    }

    // Update is called once per frame
    void Update () {
        myTweener.Play();
    }
}

消失效果(文字)

void Update(){
     if(Input.GetKey(KeyCode.K)){
            killTips.text = string.Format("{0} 殺", ScoreManager.score1);
            killTips.color = new Color(0.94f,0.32f,0.32f,1);
            //print("k");
            killTips.DOFade(0, 2);
        }
}

控制流程

void Start() {
    myTweener2 = killTips.DOFade(0, 1f);
    myTweener2.SetAutoKill(false);// 不自動消失掉動畫
    myTweener2.Pause();     // 一播放就暫停
}

// tip相當於觸發點
void Update(){
    if(tip){
            tip = false;
            myTweener2.Restart();
            myTweener2.Pause();
            killTips.text = string.Format("{0} 殺", ScoreManager.score1);
            killTips.color = new Color(0.94f,0.32f,0.32f,1);
            //print("k");
            StartCoroutine(SleepAndTips(2));
        }
}

// 延遲函式 (延遲tips)
IEnumerator SleepAndTips(float s)
 {
     yield return new WaitForSeconds(s);
     //killTips.DOFade(0, 1f);
     myTweener2.Play();
 }

相關文章