1. 程式人生 > >UGUI 之 製作角色受傷螢幕變紅的動畫提示(三)

UGUI 之 製作角色受傷螢幕變紅的動畫提示(三)

做一個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;

	}

	
}

二、截圖