UGUI动画效果

xiaoxiao2021-02-28  64

添加流光效果

建立两个图片,父物体白图,子物体流光特效

子图片编写脚本

publicclassEffect01 : MonoBehaviour {

    publicSprite[] sprites;

    privateImage bgImage;

         // Use this for initialization

         void Start () {

        Array.Sort(sprites, (x, y) => { return x.name.CompareTo(y.name); });

        bgImage = GetComponent<Image>();

         }

    float count = 0;

    int index = 0;

         // Update is called once per frame

         void Update () {

        count++;

        if (index == sprites.Length -1)

        {

            index = 0;

        }

        else

        {

            index++;

        }

        bgImage.sprite = sprites[index];

        count = 0;

         }

}

给子物体插入图片时右上角上锁,插入十六张图片,运行后显示流光图

 

买装备时装备明暗变化即购买过程变化

创建一个Button按钮,插入精灵图片,Reset初始化,创建一个图片作为子物体,插入Button中插入的图片,颜色调灰一点,透明度调第一半,Fill Origin调成Top

publicclassCDEffect : MonoBehaviour {

    publicfloat leftTime;

    publicfloat totalTime;

    privateImage effectImage;

    privateButton cdButton;

         // Use this for initialization

         void Start () {

        effectImage = transform.FindChild("Image").GetComponent<Image>();

        leftTime = totalTime;

        cdButton = transform.GetComponent<Button>();

        cdButton.interactable = false;

         }

         // Update is called once per frame

         void Update () {

        leftTime -= Time.deltaTime;

        if (effectImage.fillAmount > 0)

        {

            effectImage.fillAmount = leftTime /totalTime;

        }

        else

        {

            effectImage.fillAmount = 0;

            cdButton.interactable = true;

        }

    }

    publicvoid FireSkill()

    {

        Debug.Log("技能使用了");

        leftTime = totalTime;

        cdButton.interactable = false;

    }     

}

调整一下两个图片的透明度,在Button按钮中的Button组件中最下面On Click插件,点击加号,左上角的不用动,左边插入按钮,右面选择CDEffect 然后选择FireSkill

给物体添加动画

①  右键Assets    创建一个Animation

②  创建一个立方块,挂载Animation组件,组件中Animation项载入刚创建的动画,size改为1,Element载入动画

③  选中立方块,ctrl+6,creat按钮保存动画,Add Propert——Transform——position控制物体的移动

④  右上角锁后面菜单改成Debug     Animation中Legacy对勾点上,显示组件中没有的项

注:position里的竖排点可以移动调整速度。

转载请注明原文地址: https://www.6miu.com/read-96323.html

最新回复(0)