LoginSignup
0
0

この記事は、【完走したい】楽しくいろいろやる Advent Calendar 2023の8日目です。

オブジェクト破壊

 public void GameFin()
    {
        if (photonView.IsMine)
        {
            Player owner = (Player)photonView.Owner;
            PhotonNetwork.Destroy(this.gameObject);
        }

    }

オーナー(管理者)の権限を渡す。
⇒オブジェクトを破壊できます。
ただし、通常のDestroyを使うとエラーが出ます。
# 勝ち負けがわかるようにする
エアホッケーなので相手のほうに入れたら本来は点が加算されますが、今回はサドンデス戦とします。
パックが奥に飛んで行ったら勝敗が出るようにします。
↓コード

  public void OnCollisionEnter(Collision collision)
    {

        if (collision.gameObject.name == "JudA")
        {
            GameObject GamePlayer = GameObject.Find("Cube(Clone)");
            id = GamePlayer.GetComponent<TFControll>().A;
            if (id == 1)
            {
                Debug.Log("1");
            }
            if (id == 2)
            {
                Debug.Log("2");
            }
            if (id == 1)
            {
                Lose.SetActive(true);

            }
            if (id == 2)
            {
                Win.SetActive(true);
            }

            if (photonView.IsMine)
            {
                Invoke("GameFin", 1f);
            }
        }
        if (collision.gameObject.name == "JudB")
        {
            Cube = GameObject.Find("Cube(Clone)");
            id = Cube.GetComponent<TFControll>().A;
            if (id == 1)
            {
                Debug.Log("1");
            }
            if (id == 2)
            {
                Debug.Log("2");
            }
            if (id == 1)
            {
                Win.SetActive(true);


            }
            if (id == 2)
            {
                Lose.SetActive(true);
            }

            if (photonView.IsMine)
            {
                Invoke("GameFin", 1f);
            }
        }





    }

2日かかりました。
Debug.Logが書いてあるところは動くか確認するた目のものなので消してOKです。
ざっくり説明すると
Cubeを見つけてAを取ってきて、idに代入
idの値に応じて勝ち負けを出します。
実は、このAの中身はプレイヤーの番号です。
詳しくは次の記事に書きます。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0