DoTween常用的API

using DG.Tweening;

public class MyText : MonoBehaviour {

    private Text text;

    // Use this for initialization
    void Start () {
        text =  this.GetComponent<Text>();
        text.DOText("进入,下一关", 2);//让文字一个一个出来的动画。
        text.DOFade(1, 10);//文字颜色渐隐渐现,1是显示,10是时间.
        text.DOColor(Color.red, 2);//改变字体颜色。


    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

 

public class MyImage : MonoBehaviour {

    // Use this for initialization
    void Start () {

       Tweener tweeners =  transform.DOLocalMoveX(0,2);

       tweeners.SetEase(Ease.InOutBack);//设置动画的运动曲线,可以选择很多种

       tweeners.SetLoops(2);//setloops是设置动画播放的循环次数。

       tweeners.OnComplete(niubi);//设置一个事件,就是动画播放完成后执行下一步,可以执行某一个函数。
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    void niubi()
    {
        Debug.Log("动画播放完成");
    }
}

public class Mycude : MonoBehaviour {

    // Use this for initialization
    void Start () {
        // transform.DOMoveX(5, 1);//单轴移动,从当前位置移动到x坐标5的位置,时间是一秒。
        //transform.DOMoveX(5, 1).From();//让物体从坐标5的地方移动到当前的位置。
        transform.DOMoveX(5, 1).From(true);//加上true之后目标位置就是一个相对位置。


    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

public class mybutton : MonoBehaviour {

    public RectTransform myimage;

    private bool Isdh = false;

    private void Start()
    {
        // myimage.DOMove(new Vector3(0, 0, 0), 3);//世界坐标
        //放在Start只创建一次,DO方法每次执行都会创建一次,如果多次点击则会消耗内存,不利于优化。
        Tweener tweeners = myimage.DOLocalMove(new Vector3(0, 0, 0), 0.5f);//移动到局部坐标,每次执行都会创建一个动画,默认动画完成后会被销毁                                                    //Tweener对象保存这个动画信息 每次调用Do类型的方法都会创建一个Tweener类型的对象,这个对象是由Dotweener来管理的。
        tweeners.SetAutoKill(false);//把自动销毁这个动能关闭。
        tweeners.Pause();//创建后让它暂停不播放
    }

    public void Buntton_Click()
    {
        if (Isdh == false)
        {
            //myimage.DOPlay();//播放一次
            myimage.DOPlayForward();//开始前放
            Isdh = true;
        }
        else
        {
            myimage.DOPlayBackwards();//开始倒放
            Isdh = false;
        }
    }
}

public class GetSart : MonoBehaviour {

    public Vector3 myvaule = new Vector3(0, 0, 0);
    public Transform mytransform;
    public RectTransform myrectTransform;
    // Use this for initialization
    void Start () {
        DOTween.To(()=>myvaule, x => myvaule = x,new Vector3(0, 0, 0), 10);//控制一个变量的变化。
    }
    
    // Update is called once per frame
    void Update () {
        //mytransform.position = myvaule;
        myrectTransform.localPosition = myvaule;
    }
}


public class myZd : MonoBehaviour {

    // Use this for initialization
    void Start () {

        transform.DOShakePosition(1,new Vector3(4,4,4));//摄像头震动效果
    }
    

public class Publc : MonoBehaviour {

    private DOTweenAnimation DoTweenAs;
    // Use this for initialization
    void Start () {

        DoTweenAs = GetComponent<DOTweenAnimation>();
        DoTweenAs.DOPlay();
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

    // Update is called once per frame
    void Update () {
        
    }
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值