当前位置:网站首页>Unity中暂停、继续播放、杀死、正放、倒放Dotween动画
Unity中暂停、继续播放、杀死、正放、倒放Dotween动画
2022-08-10 05:35:00 【三和尚】
此案例是控制material(材质球)的alpha(透明度)值,对有MeshRenderer的Model外观有不停的渐隐渐显效果
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Demo01 : MonoBehaviour
{
/// <summary>
/// Model的MeshRenderer
/// </summary>
public MeshRenderer meshRenderer;
private void Start()
{
Color color= meshRenderer.material.color;
color.a = 120f / 255f;
MyPingPong(meshRenderer.material.color,color);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
DOTween.Pause("move"); //只暂停ID为move的动画,可以继续播放
}
if (Input.GetKeyDown(KeyCode.W))
{
DOTween.Play("move"); //继续播放ID为move
}
if (Input.GetKeyDown(KeyCode.E))
{
DOTween.Kill("move"); //杀死ID为move补间动画,不能再播放
}
if (Input.GetKeyDown(KeyCode.R))
{
DOTween.PlayForward("move"); //正放ID为move动画
}
if (Input.GetKeyDown(KeyCode.T))
{
DOTween.PlayBackwards("move"); //倒放ID为move动画,倒放不会循环
}
}
/// <summary>
/// 控制Model渐隐渐显效果
/// </summary>
private void MyPingPong(Color a, Color b)
{
DOTween.To(()=>meshRenderer.material.color,x=>meshRenderer.material.color=x,b,0.5f).OnComplete(()=>MyPingPong(b,a)).SetId<Tween>("move");
}
}
边栏推荐
猜你喜欢
随机推荐
pytorch-10. Convolutional Neural Networks
PyTorch的安装与基础知识
以STM32F103C6T6为例通过配置CubeMX实现EXIT外部中断
序列化、编码、requests库json和data参数
【fiddler2】使用fiddler mock response 数据
51单片机ST188手持人体温度脉搏心率测量仪锂电池充电
详解 Hough 变换(上)基本原理与直线检测
Unity中Xml简介以及通过脚本读取Xml文本中的内容
51单片机BH1750智能补光灯台灯光强光照恒流源LED控制系统
STM32F407ZG PWM
Exploratory Data Analysis EDA
【简易笔记】PyTorch官方教程简易笔记 EP4
【图像识别】训练一个最最简单的AI使其识别Vtuber
STM32F407ZG TIM通用定时器
pytorch-10.卷积神经网络(作业)
[Difference between el and template]
Collection set interface
Test of the opposite sex what you look like?
菜谱小程序源码免费分享【推荐】
【简易笔记】PyTorch官方教程简易笔记 EP3