赞
踩
下载Sotween插件文件,放入Assets文件目录下面,即可
随着时间的进行改变颜色,并实现物体移动的同时旋转。
引入名词空间
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秒变蓝
- }
- }
-
-
-
效果
键盘输入A则移动的同时旋转
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。