HPが0になった時の処理





KOラベルの表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;
// ★追加
using TMPro;
public class PlayerHealth : MonoBehaviourPunCallbacks
{
private int maxHP = 10;
private int HP;
public Slider hpSlider;
// ★追加
private TextMeshProUGUI koLabel;
void Start()
{
HP = maxHP;
hpSlider.maxValue = HP;
hpSlider.value = HP;
// ★追加
koLabel = GameObject.Find("KOLabel").GetComponent<TextMeshProUGUI>();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Trigger"))
{
HP -= 1;
print(photonView.Owner.NickName + HP);
hpSlider.value = HP;
// ★追加
if (HP < 1)
{
this.gameObject.SetActive(false);
koLabel.text = photonView.Owner.NickName + " KO!";
}
photonView.RPC("Damage", RpcTarget.Others);
}
}
// RPC→リモート・プロシージャ・コールの略称
// 相手に「ここで定義したメソッド」を「実行」してもらう仕組み
[PunRPC]
void Damage()
{
HP -= 1;
print(photonView.Owner.NickName + HP);
hpSlider.value = HP;
// ★追加
if (HP < 1)
{
this.gameObject.SetActive(false);
koLabel.text = photonView.Owner.NickName + " KO!";
}
}
}

【2021版】BattleOnline(全37回)
他のコースを見る




KOラベルの表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;
// ★追加
using TMPro;
public class PlayerHealth : MonoBehaviourPunCallbacks
{
private int maxHP = 10;
private int HP;
public Slider hpSlider;
// ★追加
private TextMeshProUGUI koLabel;
void Start()
{
HP = maxHP;
hpSlider.maxValue = HP;
hpSlider.value = HP;
// ★追加
koLabel = GameObject.Find("KOLabel").GetComponent<TextMeshProUGUI>();
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Trigger"))
{
HP -= 1;
print(photonView.Owner.NickName + HP);
hpSlider.value = HP;
// ★追加
if (HP < 1)
{
this.gameObject.SetActive(false);
koLabel.text = photonView.Owner.NickName + " KO!";
}
photonView.RPC("Damage", RpcTarget.Others);
}
}
// RPC→リモート・プロシージャ・コールの略称
// 相手に「ここで定義したメソッド」を「実行」してもらう仕組み
[PunRPC]
void Damage()
{
HP -= 1;
print(photonView.Owner.NickName + HP);
hpSlider.value = HP;
// ★追加
if (HP < 1)
{
this.gameObject.SetActive(false);
koLabel.text = photonView.Owner.NickName + " KO!";
}
}
}

HPが0になった時の処理