ガストラップ&プレーヤーダメージ
ポイズントラップ
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);
}
}
// ★追加(ポイズントラップ)
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("PoisonTrap"))
{
count += 1;
// 一定時間ごとにHPが減少する。
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);
}
}
// ★追加(ポイズントラップ)
private void OnTriggerStay(Collider other)
{
if (other.CompareTag("PoisonTrap"))
{
count += 1;
// 一定時間ごとにHPが減少する。
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");
}
}
ガストラップ&プレーヤーダメージ