実現したいこと
2人のプレイヤー(キャラクター)をジャンプボタンで同時にジャンプさせたい
(PlayerControllerとPlayer2Controller)
発生している問題・分からないこと
PlayerControllerを充てた方のキャラクターのみジャンプする
片方しかジャンプできない
Player2Controllerを充てたキャラクターもジャンプさせたいが方法がわからない
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //UIを使う public class GameMamager : MonoBehaviour { public GameObject mainImage; public Sprite gameOverSpr; public Sprite gameClearSpr; public GameObject panel; public GameObject restartButton; public GameObject nextButton; //サウンド再生追加// public AudioClip meGameOver;//ゲームオーバー public AudioClip meGameClear;//ゲームクリア Image titleImage; //++プレイヤー操作++// public GameObject inputUI; //操作UIパネル // Start is called before the first frame update void Start() { //画像を非表示 Invoke("InactiveImage", 1.0f); //ボタンとパネルを非表示 panel.SetActive(false); } // Update is called once per frame void Update() { if (PlayerController.gameState == "gameclear") { //ゲームクリア mainImage.SetActive(true); panel.SetActive(true); //RESTARTボタンを無効化にする Button bt = restartButton.GetComponent<Button>(); bt.interactable = false; mainImage.GetComponent<Image>().sprite = gameClearSpr; PlayerController.gameState = "gameend"; //サウンド再生追加 //サウンド再生 AudioSource soundPlayer = GetComponent<AudioSource>(); if (soundPlayer != null) { //BGM停止 soundPlayer.Stop(); soundPlayer.PlayOneShot(meGameClear); } //++プレイヤー操作++// inputUI.SetActive(false); //操作UI隠す } else if (PlayerController.gameState == "gameover") { //ゲームオーバー mainImage.SetActive(true); panel.SetActive(true); //NEXTボタンを無効化にする Button bt = nextButton.GetComponent<Button>(); bt.interactable = false; mainImage.GetComponent<Image>().sprite = gameOverSpr; PlayerController.gameState = "gameend"; //サウンド再生追加 //サウンド再生 AudioSource soundPlayer = GetComponent<AudioSource>(); if (soundPlayer != null) { //BGM停止 soundPlayer.Stop(); soundPlayer.PlayOneShot(meGameOver); } //++プレイヤー操作++// inputUI.SetActive(false); //操作UI隠す } else if (PlayerController.gameState == "playing") { //ゲーム中 } } //画像を非表示にする void InactiveImage() { mainImage.SetActive(false); } //++プレイヤー操作++// //ジャンプ public void Jump() { GameObject player = GameObject.FindGameObjectWithTag("Player"); PlayerController playerCnt = player.GetComponent<PlayerController>(); playerCnt.Jump(); } }
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
エラーがでてしまう
片方しかジャンプしない
補足
特になし
> エラーがでてしまう
そのエラーの内容を記載してください。
あと、質問とは関係ない話ですが、GameMamagerのようなクラスにジャンプ処理を書くのは、設計してあまりよくないような気がします。
やり方が全く分からず error CS1525: Invalid expression term ')'になりました
そうなんですね、書籍を参考にしていたのですが設計的に良くないんですね
コメントありがとうございます
このエラーはカッコの数が合っていない的な文法ミスでしょう。
そこに気を付けてもう一度やってみてください。
もし同じエラーが出たら、そのコード内容を追記してください。
> 書籍を参考にしていたのですが
私が言いたいのは、「GameMamagerを作るな」ではなく「GameMamagerはゲーム全体の処理を書くのであって、プレイヤーの操作はプレイヤーのスクリプトに書くべき」という意味です。
「あなたの処理の追加の仕方」が悪いのであって、「書籍のコード」が悪いとは一言も言っていません。
書籍そのままなので
すみませんちょっとわからないです
ありがとうございました
回答1件
あなたの回答
tips
プレビュー