プレイヤーが「ビリビリ」というオブジェクトに触れたらintが1になり、
スコアのクラスでifでintが1になったかどうかを判定したいのですが
静的でないフィールド、メソッド~~オブジェクト参照が必要です。とエラーが出てしまいます。どうすればよいのでしょうか?
以下、該当のコードになります。
プレイヤー側
C#
1public class Player : MonoBehaviour 2{ 3 4 public static int Hosi; 5 6 void Start() 7 { 8 Hosi = 0; 9 } 10 11 12 //ビリビリというタグのオブジェクトに当たったら 13 void OnCollisionEnter2D(Collision2D collision) 14 { 15 if (collision.gameObject.tag == "biribiri") 16 { 17 Hosi = 1; 18 19 } 20 21 } 22
スコア側
C#
1public class Score : MonoBehaviour 2{ 3 4 // スコアを表示する 5 public Text scoreText; 6 // ハイスコアを表示する 7 public Text highScoreText; 8 9 // スコア 10 public int score; 11 12 // ハイスコア 13 public int highScore; 14 15 // PlayerPrefsで保存するためのキー 16 public string highScoreKey = "highScore"; 17 18 //一秒ごとにスコアが1増える 19 [SerializeField] 20 private float interval = 1f; 21 [SerializeField] 22 private float tmpTime = 0; 23 24 int ScoreHosi; 25 26 void Start() 27 { 28 29 score = PlayerPrefs.GetInt("Score", 0); 30 31 } 32 33 void Update() 34 { 35 // スコアがハイスコアより大きければ 36 if (highScore < score) 37 { 38 highScore = score; 39 } 40 41 // スコア・ハイスコアを表示する 42 scoreText.text = score.ToString(); 43 highScoreText.text = highScore.ToString(); 44 45 int ScoreHosi = Player.Hosi; 46 47 } 48 49 void FixedUpdate() 50 { 51 //1秒ずつ増える命令 52 tmpTime += Time.deltaTime; 53 if (tmpTime >= interval) 54 { 55 score += 10; 56 57 tmpTime = 0; 58 } 59 } 60 61 // ゲーム開始前の状態に戻す 62 private void Initialize() 63 { 64 // スコアを0に戻す 65 score = 0; 66 67 // ハイスコアを取得する。保存されてなければ0を取得する。 68 highScore = PlayerPrefs.GetInt(highScoreKey, 20000); 69 } 70 71 // ポイントの追加 72 public void AddPoint(int point) 73 { 74 score = score + point; 75 } 76 77 // ハイスコアの保存 78 public void Save() 79 { 80 // ハイスコアを保存する 81 PlayerPrefs.SetInt(highScoreKey, highScore); 82 PlayerPrefs.Save(); 83 84 } 85 86 public static void Pause() 87 { 88 if(ScoreHosi == 1) 89 { 90 Time.timeScale = 0; 91 } 92 } 93 94}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/31 03:39