電流トラップ&プレーヤーダメージ








電流トラップ
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;
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);
}
}
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;
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);
}
}
void GoToGameover()
{
SceneManager.LoadScene("GameOver");
}
}



電流トラップ&プレーヤーダメージ