- 在UI中添加一个覆盖全屏幕的红色图片,设置透明度为0。
- 添加变量控制闪动速度
- 当角色受到攻击时转换透明度,然后用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;
}