使用Button 控制DoTween

using UnityEngine;
using System.Collections;
using DG.Tweening;
public class TheExplosionFigure : MonoBehaviour {
//动画要到达的目标位置
public Vector3 TheTargetLocation;
//动画所需要的时间
public float duration;
//目标物体
public Transform TargetPart;
//是否处于展开状态
public bool IsSpread;
//是否完全展开了模型
public bool FullyExpanded;

public bool Reset;

public Vector3 StartPosition;
//模型当前的位置
private  Transform  currentLocation;


// Use this for initialization
void Start () {
    //当前位置
    currentLocation = GetComponent();
    TargetPart = GetComponent();

    StartPosition = TargetPart.position;
    //是否展开模型
    IsSpread = false;
    Reset = true;
    //是否完全展开
    FullyExpanded = false;
    //从当前位置到目标位置的过度 
    Tweener tweener = TargetPart.DOMove(TheTargetLocation, duration);
    //自动销毁设置为false
    tweener.SetAutoKill(false );
    //动画暂停 
    tweener.Pause();
}
//public void IsFullyExpanded()
//{
    
//}
// Update is called once per frame
void Update () {
    //如果当前的位置 = 目标位置
    if (currentLocation.position == TheTargetLocation)
    {
        //完全展开了
        FullyExpanded = true;
        Reset = false;
    }
    //如果当前位置 不等于 目标位置
     else
    if (currentLocation.position == StartPosition)
    {
        //没有完全展开
        FullyExpanded = false;
        Reset = true;
    }

}
//Button点击事件
public void OnClick()
{
    
        //如果没有处于展开状态
        if (IsSpread == false)
        {

        //如果模型没有完全展开
        if (Reset)
        {
            //前放展开动画
            TargetPart.DOPlayForward();
            IsSpread = true;
        }

    }

       // FullyExpanded = true;
    

    else 
        //如果模型处于展开状态
        if (IsSpread)
        {
        //如果模型完全展开了
        if (FullyExpanded)
        {
            //倒放展开动画(合拢模型)
            TargetPart.DOPlayBackwards();
            IsSpread = false;
        }
         //FullyExpanded = false;
       
    }
    
}

}

你可能感兴趣的:(使用Button 控制DoTween)