PlayerのHPの作成


PlayerのHP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerHealth : MonoBehaviourPunCallbacks
{
private int maxHP = 10;
private int HP;
void Start()
{
HP = maxHP;
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Trigger"))
{
HP -= 1;
print(photonView.Owner.NickName + HP);
// Damageという名前のメソッドを相手プレーヤーに実行してもらう。
// 「あなたは私の画面内でダメージを受けてHPが1減ったので、そちらでも同じように処理してね。」という依頼
photonView.RPC("Damage", RpcTarget.Others);
}
}
// RPC→リモート・プロシージャ・コールの略称
// 相手に「ここで定義したメソッド」を「実行」してもらう仕組み
[PunRPC]
void Damage()
{
HP -= 1;
print(photonView.Owner.NickName + HP);
}
}

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

PlayerのHP
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class PlayerHealth : MonoBehaviourPunCallbacks
{
private int maxHP = 10;
private int HP;
void Start()
{
HP = maxHP;
}
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("Trigger"))
{
HP -= 1;
print(photonView.Owner.NickName + HP);
// Damageという名前のメソッドを相手プレーヤーに実行してもらう。
// 「あなたは私の画面内でダメージを受けてHPが1減ったので、そちらでも同じように処理してね。」という依頼
photonView.RPC("Damage", RpcTarget.Others);
}
}
// RPC→リモート・プロシージャ・コールの略称
// 相手に「ここで定義したメソッド」を「実行」してもらう仕組み
[PunRPC]
void Damage()
{
HP -= 1;
print(photonView.Owner.NickName + HP);
}
}

PlayerのHPの作成