Unity基础入门分享

Unity3D 角色受攻击,画面闪动变红

2018-01-02  本文已影响175人  醉杀楚天白
  1. 在UI中添加一个覆盖全屏幕的红色图片,设置透明度为0。
  2. 添加变量控制闪动速度
  3. 当角色受到攻击时转换透明度,然后用lerp差值清空颜色。

关键代码如下

        void Update ()
        {
            // If the player has just been damaged...
            if(damaged)
            {
                // ... set the colour of the damageImage to the flash colour.
                damageImage.color = flashColour;
            }
            // Otherwise...
            else
            {
                // ... transition the colour back to clear.
                damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
            }

            // Reset the damaged flag.
            damaged = false;
        }
上一篇下一篇

猜你喜欢

热点阅读