usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingDG.Tweening;//引入命名空间publicclassTest01:MonoBehaviour{
publicVector3 myValue =newVector3(1000,0,0);//初始位置publicRectTransform taskPanelTransform;// Start is called before the first frame updatevoidStart(){
//对变量做一个动画(通过插值的方式去修改一个值的变化)
DOTween.To(()=> myValue, x => myValue = x,newVector3(0,0,0),3);}// Update is called once per framevoidUpdate(){
//taskPanelTransform.position = myValue; //修改世界坐标
taskPanelTransform.localPosition = myValue;//修改局部坐标}}
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingDG.Tweening;publicclassTest03:MonoBehaviour{
// Start is called before the first frame updatevoidStart(){
//当前位置1//默认是3秒内从当前位置1移动到目标位置5//transform.DOMoveX(5, 3);//加上From()方法以后表示3秒内从目标位置5移动到当前位置1//transform.DOMoveX(5, 3).From();//加上true参数以后表示3秒内从相对目标位置6移动到当前位置1
transform.DOMoveX(5,3).From(true);}}
4、动画属性设置
效果展示
代码
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingDG.Tweening;publicclassTest04:MonoBehaviour{
// Start is called before the first frame updatevoidStart(){
//当前位置1000Tweener tweener = transform.DOLocalMoveX(0,3);//3秒内从当前位置1000移动到目标位置0
tweener.SetEase(Ease.OutBack);//修改动画曲线
tweener.SetLoops(2);//设置动画循环次数
tweener.OnComplete(OnTweenComplete);//当动画播放完成时会调用该事件}privatevoidOnTweenComplete(){
Debug.Log("动画播放完毕!");}}
5、文字动画
效果展示
代码
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingDG.Tweening;usingUnityEngine.UI;publicclassTest05:MonoBehaviour{
privateText text;// Start is called before the first frame updatevoidStart(){
text =this.GetComponent<Text>();
text.DOText("允许到达目的地的路途有一些坎坷 允许自己偶尔不开心不聪明 也允许偶尔做得不够好 但不会轻易放弃 时间在走 很多事都会过去都会慢慢变好",10);
text.DOColor(Color.red,10);//修改文字的颜色
text.DOFade(1,3);//修改文字的透明度}}
6、屏幕震动
效果展示
代码
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingDG.Tweening;publicclassTest06:MonoBehaviour{
// Start is called before the first frame updatevoidStart(){
//transform.DOShakePosition(1); //摄像机震动1秒
transform.DOShakePosition(1,newVector3(3,3,0));//改变摄像机的震动幅度}}