勝者に「Winner」の表示を行う


勝者の判定
using UnityEngine;
using Photon.Pun;
using TMPro;
public class ResultManager : MonoBehaviour
{
public TextMeshProUGUI playerlabel_1;
public TextMeshProUGUI playerLabel_2;
private const string P1_NAME = "p1n";
private const string P2_NAME = "p2n";
private const string P1_SCORE = "p1s";
private const string P2_SCORE = "p2s";
// ★追加
public GameObject winnerIcon_1;
public GameObject winnerIcon_2;
public GameObject drawIcon;
private int p1Score;
private int p2Score;
void Start()
{
ShowResult();
}
void ShowResult()
{
var props = PhotonNetwork.CurrentRoom.CustomProperties;
if (props.ContainsKey(P1_NAME) && props.ContainsKey(P1_SCORE))
{
string p1Name = props[P1_NAME].ToString();
// ★改良
// intを削除する
p1Score = (int)props[P1_SCORE];
playerlabel_1.text = p1Name + ": " + p1Score.ToString("D4");
}
if (props.ContainsKey(P2_NAME) && props.ContainsKey(P2_SCORE))
{
string p2Name = props[P2_NAME].ToString();
// ★改良
// intを削除する
p2Score = (int)props[P2_SCORE];
playerLabel_2.text = p2Name + ": " + p2Score.ToString("D4");
}
// ★追加
// 勝者アイコンの表示
if (p1Score > p2Score)
{
winnerIcon_1.SetActive(true);
}
else if (p1Score < p2Score)
{
winnerIcon_2.SetActive(true);
}
else
{
drawIcon.SetActive(true);
}
}
}



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

勝者の判定
using UnityEngine;
using Photon.Pun;
using TMPro;
public class ResultManager : MonoBehaviour
{
public TextMeshProUGUI playerlabel_1;
public TextMeshProUGUI playerLabel_2;
private const string P1_NAME = "p1n";
private const string P2_NAME = "p2n";
private const string P1_SCORE = "p1s";
private const string P2_SCORE = "p2s";
// ★追加
public GameObject winnerIcon_1;
public GameObject winnerIcon_2;
public GameObject drawIcon;
private int p1Score;
private int p2Score;
void Start()
{
ShowResult();
}
void ShowResult()
{
var props = PhotonNetwork.CurrentRoom.CustomProperties;
if (props.ContainsKey(P1_NAME) && props.ContainsKey(P1_SCORE))
{
string p1Name = props[P1_NAME].ToString();
// ★改良
// intを削除する
p1Score = (int)props[P1_SCORE];
playerlabel_1.text = p1Name + ": " + p1Score.ToString("D4");
}
if (props.ContainsKey(P2_NAME) && props.ContainsKey(P2_SCORE))
{
string p2Name = props[P2_NAME].ToString();
// ★改良
// intを削除する
p2Score = (int)props[P2_SCORE];
playerLabel_2.text = p2Name + ": " + p2Score.ToString("D4");
}
// ★追加
// 勝者アイコンの表示
if (p1Score > p2Score)
{
winnerIcon_1.SetActive(true);
}
else if (p1Score < p2Score)
{
winnerIcon_2.SetActive(true);
}
else
{
drawIcon.SetActive(true);
}
}
}



勝者に「Winner」の表示を行う