■概要
相手プレイヤーのスクリプト内の変数が正常に取得できません。
原因がわからないため、お力をおかしください。
■詳細
1対1のオンライン対戦ゲームです。プレイヤー名は、Player[1]とPlayer[2]です。
自分がゴールに触れると、自身のjudge変数に"win"が入ります。
相手のプレイヤーのjudge変数に"win"が入っていた場合、自身の負けとします。
勝敗状況を判断するため、相手のjudge変数をFindとGetComponentでリアルタイムで取得します。
しかし取得が正常に出来ておらず、相手がゴールし、相手のjudgeにwinが代入されても、
自分は相手のjudgeの状態が把握されません。(初期値の取得はできている様子で、永久に空の""のまま)
エラーは出ておりません。
■コード
省略 public GameObject enemy = null; //敵のオブジェクト UnityChan.UnityChanControlScriptWithRgidBody script_enemy = null; //敵のオブジェクトのスクリプト public string judge = ""; //自身の勝敗判定用 win or lose 省略 void Start () { 省略 } void FixedUpdate () { 省略 //★敵がいる場合、敵スクリプトの状態をリアルタイムで取得 if (players.Length == 2) { //自身のチーム名を元に敵プレイヤー名を判断し、enemyオブジェクトに敵のオブジェクトを入れる if (team == "red") { enemy = GameObject.Find("Player[" + 2 + "]"); } else { enemy = GameObject.Find("Player[" + 1 + "]"); } //スクリプトも取得 script_enemy = enemy.GetComponent<UnityChan.UnityChanControlScriptWithRgidBody>(); Debug.Log("script_enemy.judge:[" + script_enemy.judge + "] judge:[" + judge + "]"); //★相手のjudgeにwinが代入されても、何故か検知できない } //勝利時の処理 Goal Collisionでjudgeにwinを代入 if (judge == "win") { //自身が勝者の場合 winorlose_object = GameObject.Find("WinOrLose"); Text winorlose_text = winorlose_object.GetComponent<Text>(); // テキストの表示を入れ替える winorlose_text.text = "おめでとう!勝利 10秒後にタイトルに戻ります"; } //★ここが作用しない。敵のjudgeが正常に取得できていない。 if(script_enemy.judge == "win") { //敗北を入力 judge = "lose"; //自身が敗者の場合 winorlose_object = GameObject.Find("WinOrLose"); Text winorlose_text = winorlose_object.GetComponent<Text>(); // テキストの表示を入れ替える winorlose_text.text = "残念…あなたの負け 10秒後にタイトルに戻ります"; totitle_time_frag = 1; Debug.Log("敗北時の処理 敗北プレイヤーは" + team); } } //ゴール着地時の処理 ★接触判定は問題なし if (photonView.IsMine && collision.gameObject.name == "Goal_Floor") { Debug.Log("★触れた"); //ゲーム終了フラグが立っていない場合 if (totitle_time_frag == 0) { //自身のjudge変数に値が入っていない場合、自身のjudge変数にwinを入れる。loseが入っている場合は処理をスルー。 //ここの判定は問題なし if (judge == "") { judge = "win"; //★ここは自身確かに代入されている Debug.Log("ゴールに触れた 勝利時の処理 judge:" + judge); } //再度判定が入らないようにフラグ処理 totitle_time_frag = 1; Debug.Log("totitle_time_fragを1に"); } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/17 04:40
2022/01/17 07:02