美文网首页Unity基础入门分享
Unity3D 角色受攻击,画面闪动变红

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

作者: 醉杀楚天白 | 来源:发表于2018-01-02 20:49 被阅读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;
            }
    

    相关文章

      网友评论

        本文标题:Unity3D 角色受攻击,画面闪动变红

        本文链接:https://www.haomeiwen.com/subject/zlgqnxtx.html