プレーヤーのステータス①(HPを設定する)

プレーヤーにHPを設定する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
public GameObject effectPrefab;
public AudioClip damageSound;
public AudioClip destroySound;
public int maxHP;
private int HP;
void Start()
{
HP = maxHP;
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("EnemyMissile"))
{
HP -= 1;
AudioSource.PlayClipAtPoint(damageSound, Camera.main.transform.position);
Destroy(other.gameObject);
if(HP == 0)
{
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 1.0f);
AudioSource.PlayClipAtPoint(destroySound, Camera.main.transform.position);
// Playerは非アクティブ状態にする(ポイント)
this.gameObject.SetActive(false);
}
}
}
}




【2021版】Danmaku(基礎/全55回)
他のコースを見る
プレーヤーにHPを設定する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
public GameObject effectPrefab;
public AudioClip damageSound;
public AudioClip destroySound;
public int maxHP;
private int HP;
void Start()
{
HP = maxHP;
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("EnemyMissile"))
{
HP -= 1;
AudioSource.PlayClipAtPoint(damageSound, Camera.main.transform.position);
Destroy(other.gameObject);
if(HP == 0)
{
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 1.0f);
AudioSource.PlayClipAtPoint(destroySound, Camera.main.transform.position);
// Playerは非アクティブ状態にする(ポイント)
this.gameObject.SetActive(false);
}
}
}
}




プレーヤーのステータス①(HPを設定する)