Unity Dotween animation

Download the Sotween plug-in file and put it under the Assets file directory.

Change colors over time, and allow objects to rotate while moving.

 

introduce noun space

DG.Tweening

Run.cs

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

public class Run : MonoBehaviour
{

    Material material;
    Tweener twe;
    // Start is called before the first frame update
    void Start()
    {
    material = GetComponent<MeshRenderer>().material;
    twe = material.DOColor(Color.red, 3); //3秒变红
    twe.OnComplete(ChangeColour); //动画播放结束时调用
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.A))
        {

            var s= DOTween.Sequence();
            s.Append(transform.DOLocalMoveX(10,10f));
            s.Join(transform.DOLocalRotate(new Vector3(100,0,0),10f));
        }

        
    }

    void ChangeColour()
    {
        twe = material.DOColor(Color.blue, 2); //2秒变蓝
    }
}



Effect

 

Keyboard input A will move and rotate at the same time

 

Guess you like

Origin blog.csdn.net/moonlightpeng/article/details/130222838