プレーヤーHPの作成
PlayerHP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 下記の2行も忘れずに記載!
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerHP : MonoBehaviour {
public int HP = 30; // 最大HP(自由に変更可能)
public Slider hpSlider;
public AudioClip soundA;
public AudioClip soundB;
void Start () {
hpSlider.value = HP;
}
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "EnemyBullet") {
Destroy (other.gameObject);
if (HP > 0) {
AudioSource.PlayClipAtPoint (soundA, Camera.main.transform.position);
} else {
AudioSource.PlayClipAtPoint (soundB, Camera.main.transform.position);
Invoke ("Retry", 1.0f);
return;
}
HP -= 1;
hpSlider.value = HP;
}
}
// 今回はHPが0になるとリスタートがかかるようにします。
void Retry(){
SceneManager.LoadScene ("Main");
}
}
EscapeCombat(メモ)
他のコースを見るPlayerHP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 下記の2行も忘れずに記載!
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayerHP : MonoBehaviour {
public int HP = 30; // 最大HP(自由に変更可能)
public Slider hpSlider;
public AudioClip soundA;
public AudioClip soundB;
void Start () {
hpSlider.value = HP;
}
void OnCollisionEnter(Collision other){
if (other.gameObject.tag == "EnemyBullet") {
Destroy (other.gameObject);
if (HP > 0) {
AudioSource.PlayClipAtPoint (soundA, Camera.main.transform.position);
} else {
AudioSource.PlayClipAtPoint (soundB, Camera.main.transform.position);
Invoke ("Retry", 1.0f);
return;
}
HP -= 1;
hpSlider.value = HP;
}
}
// 今回はHPが0になるとリスタートがかかるようにします。
void Retry(){
SceneManager.LoadScene ("Main");
}
}
プレーヤーHPの作成