无标题文章

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;

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

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

        StartPosition = TargetPart.position;
        //是否展开模型
        IsSpread = false;
        Reset = true;
        //是否完全展开
        FullyExpanded = false;
        //从当前位置到目标位置的过度 
        Tweener tweener = TargetPart.DOMove(TheTargetLocation, duration);
        tweener.SetEase(Ease.Linear);
        //自动销毁设置为false
        tweener.SetAutoKill(false );
        //动画暂停 
        tweener.Pause();
    }
    
    // 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;
           
        }
        
    }

    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • using UnityEngine; using System.Collections; public class...
    段然丶阅读 200评论 0 0
  • 其实我真的很喜欢这样视角很宏观的书。先对事情有个宏观的概念,再去细致了解,会对这个事物的理解更加深刻和清楚。 若是...
    冰洛洛阅读 179评论 0 1
  • 感恩妈妈,早上虽然不想离开自己温暖的小被窝,但还是起来送我去上课。 感恩古筝老师,为我不想让我饿肚子,...
    北海以南安静溺蓝_7f4d阅读 291评论 0 4