JankenManager
1 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using UnityEngine.SceneManagement; 6 7public class JankenManager : MonoBehaviour { 8 9 public GameManager gameManager; 10 11 public GameObject[] enemyObjects; 12 private int enemyHand; 13 14 private float hansyaTime; 15 private float recodeTime; 16 private float recode; 17 private static float ave=0.0; 18 19 public int countNumber; 20 21 public Text winloseText; 22 public Text resultText; 23 24 // Use this for initialization 25 void Start () { 26 PlayStart (); 27 } 28 29 // Update is called once per frame 30 void Update () { 31 32 } 33 34 void PlayStart(){ 35 winloseText.text = ""; 36 hansyaTime = 0.0f; 37 countNumber = 0; 38 hansyaTime += Time.deltaTime; 39 enemyHand = Random.Range (0, enemyObjects.Length); 40 foreach (GameObject obj in enemyObjects) { 41 obj.SetActive (false); 42 } 43 Invoke ("PlayObjects", 0.5f); 44 } 45 46 public static void PushButton(int playHand){ 47 CountUp (); 48 if ((playHand == 0 && enemyHand == 2) || 49 (playHand == 1 && enemyHand == 0) || 50 (playHand == 2 && enemyHand == 1)) { 51 winloseText.text = "成功"; 52 gameManager.ScoreUp (); 53 } else { 54 winloseText.text = "失敗"; 55 gameManager.ScoreErr (); 56 } 57 Invoke ("PlayStart", 1.0f); 58 recodeTime = hansyaTime; 59 recode += recodeTime; 60 ave = recode / countNumber; 61 resultText.text = "結果"+ave.ToString (); 62 } 63 64 void PlayObjects(){ 65 enemyObjects [enemyHand].SetActive (true); 66 } 67 68 void CountUp(){ 69 countNumber++; 70 } 71 72}
GameManager
1 2using UnityEngine.SceneManagement; 3 4public class GameManager : MonoBehaviour { 5 private float maxTime=60.0f; 6 int seconds; 7 public Text timerText; 8 9 public static int errorNumber; 10 public static int nowNumber; 11 public Text counterText; 12 13 private bool isNowGame; 14 15 void GameStart(){ 16 nowNumber = 0; 17 errorNumber = 0; 18 isNowGame = true; 19 } 20 21 22 // Use this for initialization 23 void Start () { 24 25 } 26 27 // Update is called once per frame 28 void Update () { 29 isNowGame = true; 30 maxTime -= Time.deltaTime; 31 seconds = (int)maxTime; 32 timerText.text = "制限時間 " + seconds.ToString (); 33 if (maxTime <= 0) { 34 isNowGame = false; 35 GameEnd (); 36 } 37 counterText.text = nowNumber.ToString () + "回成功"; 38 } 39 40 public static int getNowNumber(){ 41 return nowNumber; 42 } 43 44 public static int getErrNumber(){ 45 return errorNumber; 46 } 47 48 void GameEnd(){ 49 SceneManager.LoadScene ("ResultScene"); 50 } 51 52 public void ScoreUp(){ 53 nowNumber++; 54 counterText.text = nowNumber.ToString (); 55 } 56 57 public void ScoreErr(){ 58 errorNumber++; 59 } 60 }
Unityを使用してゲームを作っているのですが、画像が表示されてボタンを押すまでの時間の平均時間を出したいと思っています。ゲームの内容としましては、制限時間(仮に60秒)の中で画像が表示されたらボタンを押すという作業を繰り返し、その画像が表示されてボタンを押すまでの時間の平均時間を出したいと思っています。
JankenManagerのコードの方に新しくタイマーを設けようとしたのですがエラーが出てしまいました。
PlayStart()が呼び出されるときに再度0秒の状態で始めたいのでhansyaTime=0にしています。
ですがPushButton()の最後の4行のところでエラーが出てしまいます。
アドバイスの程よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー