UGUI 制作角色受伤屏幕变红的动画提示
发表于2018-08-21
在一些射击类的游戏中,当游戏角色受到别人的攻击时,人物会处于掉血状态,并且屏幕有变红的动画效果,本篇文章就是基于此,给大家介绍角色受伤屏幕变红的动画提示。
一、源代码
using UnityEngine; using System.Collections; using UnityEngine.UI; public class PlayerDamageAnim : MonoBehaviour { public Image damage_Image; public Color flash_Color; public float flash_Speed = 5; bool damaged = false; // Update is called once per frame void Update () { //测试的输入代码段 if(Input.GetMouseButtonDown(0)){ TakeDamage(); } PlayDamagedEffect (); } /// <summary> /// 角色受伤后的屏幕效果 /// </summary> void PlayDamagedEffect(){ if (damaged) { damage_Image.color = flash_Color; } else { damage_Image.color = Color.Lerp(damage_Image.color,Color.clear,flash_Speed * Time.deltaTime); } damaged = false; } /// <summary> /// 角色受伤 /// </summary> public void TakeDamage(){ damaged = true; } }
二、截图
