做一个FPS设计游戏中常用的角色受伤后的屏幕变红提示
一、源代码
- /// <summary>
- /// 时间:2014-4-8
- /// 作者:GWL
- /// 描述:
- /// </summary>
- 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;
- }
- }
二、截图