unity animation 动画一边播放一边缩小

    public Animation anim;

    //动画

    public GameObject btn;

    //按钮

    private Vector3 sx = new Vector3(0.02f, 0.02f, 0.02f);

    //缩小系数,缩小系数越小缩小用到的时间越慢

    private bool suo = false;

    private bool fang = false;

    private void Update()

    {

        //缩小

        if(suo==true)

        {

            anim.gameObject.transform.localScale = anim.gameObject.transform.localScale- sx;

            if(anim.gameObject .transform .localScale.x <= 3.5f)

            {

                anim.gameObject.transform.localScale = new Vector3(3.5f, 3.5f, 3.5f);

                suo = false;

            }

        }

        //放大

        if (fang  == true)

        {

            anim.gameObject.transform.localScale = anim.gameObject.transform.localScale + sx;

            if (anim.gameObject.transform.localScale.x >= 6f)

            {

                anim.gameObject.transform.localScale = new Vector3(6f, 6f, 6f);

                fang  = false;

            }

        }

    }

    public void OnClick1()

    {

        anim.Play(“baozha”);//爆炸播放

        btn.SetActive(false);

        //缩小

        suo = true;

        anim.gameObject.transform.localScale = new Vector3(6f, 6f, 6f);

    }

    public void OnClick2()

    {

        anim.Play(“huanyuan”);//还原播放

        btn.SetActive(true);

        fang = true;

        anim.gameObject.transform.localScale = new Vector3(3.5f, 3.5f, 3.5f);

    }

    原文作者:南极冰魄
    原文地址: https://blog.csdn.net/weixin_41071087/article/details/79097105
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞