using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class Test : MonoBehaviour {
private Image testImage;
private Tween maskTween;
public float times = 5f;
// Use this for initialization
private void Awake()
{
testImage = transform.GetComponent<Image>();
}
void Start () {
#region
通过颜色变换
1静态方法的使用
//DOTween.To(
// () => testImage.color, //动画要改变的属性值
//toColor => testImage.color = toColor, //DoTween每次经过计算的Alpha通道值 赋值给 要改变的对象
//new Color(1, 2, 3, 0), //颜色改变成()中的颜色
//times //动画播放的时间
// );
#endregion
//V3指的是跳的方向,50f指的是跳的力度,10000指的是跳的次数,10000指的是跳的时间,最后false指的是是否突然停止
Tween jumpTween = transform.DOLocalJump(Vector3.forward, 50f, 10, 10 , false); //将这个跳动赋值给 jumpTween
jumpTween.OnComplete(ColorHide); //调用下面私有的方法 当跳动结束后颜色消失
maskTween.SetAutoKill(false); //设置自动死亡
maskTween.Pause(); //设置暂停
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0))
{
maskTween.PlayForward(); //正面移动
maskTween = transform.DOLocalMoveX(10000, 100f); //沿着X轴移动 (目的坐标,移动速度)
}
if (Input.GetMouseButton(1))
{
maskTween.PlayBackwards(); //反向移动
maskTween = transform.DOLocalMoveX(-100000, 1000f); //同上
}
}
private void ColorHide()
{
DOTween.To(
() => testImage.color,
toColor => testImage.color = toColor,
new Color(0, 0, 0, 0), 2f //2s后将颜色变为(0,0,0,0)
);
}
}
DoTween的基本用法
最新推荐文章于 2024-01-17 17:55:13 发布