プレーヤーがダメージを受けた場合の表現







ダメージを可視化する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour {
public int playerHP;
public AudioClip damageSound;
private Image damageScreenImage;
private Color color;
void Start(){
damageScreenImage = GameObject.Find("DamageScreen").GetComponent<Image>();
// a(アルファ値)0は透明
color = damageScreenImage.color;
color.a = 0.0f;
damageScreenImage.color = color;
}
void OnCollisionEnter(Collision other){
if(other.gameObject.tag == "EnemyBullet"){
playerHP -= 1;
Destroy(other.gameObject);
AudioSource.PlayClipAtPoint(damageSound, Camera.main.transform.position);
// ★ポイント
// a(アルファ値)は「0から1の範囲」でfloat値
// ダメージを受けるたびごとに透明度を落としていく。
color.a += 0.1f;
damageScreenImage.color = color;
}
}
}



EscapeCombat
他のコースを見る






ダメージを可視化する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour {
public int playerHP;
public AudioClip damageSound;
private Image damageScreenImage;
private Color color;
void Start(){
damageScreenImage = GameObject.Find("DamageScreen").GetComponent<Image>();
// a(アルファ値)0は透明
color = damageScreenImage.color;
color.a = 0.0f;
damageScreenImage.color = color;
}
void OnCollisionEnter(Collision other){
if(other.gameObject.tag == "EnemyBullet"){
playerHP -= 1;
Destroy(other.gameObject);
AudioSource.PlayClipAtPoint(damageSound, Camera.main.transform.position);
// ★ポイント
// a(アルファ値)は「0から1の範囲」でfloat値
// ダメージを受けるたびごとに透明度を落としていく。
color.a += 0.1f;
damageScreenImage.color = color;
}
}
}



プレーヤーがダメージを受けた場合の表現