敵の攻撃でダメージを受ける

敵のビーム攻撃でダメージを受ける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerHP : MonoBehaviour
{
public int maxHP;
public AudioClip sound;
public int currentHP;
public CameraShake camShake;
public AudioClip sparkSound;
public AudioClip poisonSound;
private int count;
private void Start()
{
currentHP = maxHP;
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if(hit.gameObject.CompareTag("BombTrap"))
{
currentHP -= 1;
AudioSource.PlayClipAtPoint(sound, transform.position);
Destroy(hit.gameObject);
camShake.Shake(0.2f, 0.1f);
if (currentHP < 1)
{
Invoke("GoToGameover", 1.5f);
}
}
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("ThunderTrap"))
{
AudioSource.PlayClipAtPoint(sparkSound, transform.position);
camShake.Shake(0.2f, 0.1f);
Invoke("GoToGameover", 1.5f);
}
// ★(追加)敵のビーム攻撃
if (other.CompareTag("EnemyBeam"))
{
currentHP -= 1;
AudioSource.PlayClipAtPoint(sound, transform.position);
Destroy(other.gameObject);
camShake.Shake(0.2f, 0.1f);
if (currentHP < 1)
{
Invoke("GoToGameover", 1.5f);
}
}
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("PoisonTrap"))
{
count += 1;
if(count % 100 == 0)
{
currentHP -= 1;
AudioSource.PlayClipAtPoint(poisonSound, transform.position);
camShake.Shake(0.2f, 0.1f);
if (currentHP < 1)
{
Invoke("GoToGameover", 1.5f);
}
}
}
}
void GoToGameover()
{
SceneManager.LoadScene("GameOver");
}
}

【2019版】X_Mission(基礎/全51回)
他のコースを見る
敵のビーム攻撃でダメージを受ける
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerHP : MonoBehaviour
{
public int maxHP;
public AudioClip sound;
public int currentHP;
public CameraShake camShake;
public AudioClip sparkSound;
public AudioClip poisonSound;
private int count;
private void Start()
{
currentHP = maxHP;
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if(hit.gameObject.CompareTag("BombTrap"))
{
currentHP -= 1;
AudioSource.PlayClipAtPoint(sound, transform.position);
Destroy(hit.gameObject);
camShake.Shake(0.2f, 0.1f);
if (currentHP < 1)
{
Invoke("GoToGameover", 1.5f);
}
}
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("ThunderTrap"))
{
AudioSource.PlayClipAtPoint(sparkSound, transform.position);
camShake.Shake(0.2f, 0.1f);
Invoke("GoToGameover", 1.5f);
}
// ★(追加)敵のビーム攻撃
if (other.CompareTag("EnemyBeam"))
{
currentHP -= 1;
AudioSource.PlayClipAtPoint(sound, transform.position);
Destroy(other.gameObject);
camShake.Shake(0.2f, 0.1f);
if (currentHP < 1)
{
Invoke("GoToGameover", 1.5f);
}
}
}
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("PoisonTrap"))
{
count += 1;
if(count % 100 == 0)
{
currentHP -= 1;
AudioSource.PlayClipAtPoint(poisonSound, transform.position);
camShake.Shake(0.2f, 0.1f);
if (currentHP < 1)
{
Invoke("GoToGameover", 1.5f);
}
}
}
}
void GoToGameover()
{
SceneManager.LoadScene("GameOver");
}
}

敵の攻撃でダメージを受ける