今リ
メイン
###前提・実現したいこと
今リズムゲームを作っていて、メインシーンのスコアをリザルトシーンで取得し表示しようと思っているのですが、取得できません。どうすればよいでしょうか。
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
//-----------メインシーン----------------
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
public GameObject[] notes; private float[] _timing; private int[] _lineNum; public string filePass; private int _notesCount = 0; private AudioSource _audioSource; private float _startTime = 0; public float timeOffset = -1; private bool _isPlaying = false; public GameObject startButton; public Text scoreText; public static int score; public string SCORE = "Score"; void Start() { score = 0; _audioSource = GameObject.Find("GameMusic").GetComponent<AudioSource>(); _timing = new float[1024]; _lineNum = new int[1024]; LoadCSV(); } void Update() { if (_isPlaying) { CheckNextNotes(); scoreText.text = score.ToString(); } } public bool IsBeat() { if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("true"); return true; } else { return false; } } public void StartGame() { startButton.SetActive(false); _startTime = Time.time; _audioSource.Play(); _isPlaying = true; } void CheckNextNotes() { while (_timing[_notesCount] + timeOffset < GetMusicTime() && _timing[_notesCount] != 0) { SpawnNotes(_lineNum[_notesCount]); _notesCount++; } } void SpawnNotes(int num) { Instantiate(notes[num], new Vector3(-4.0f + (2.0f * num), 0, 0), Quaternion.identity); } void LoadCSV() { int i = 0; TextAsset csv = Resources.Load(filePass) as TextAsset; StringReader reader = new StringReader(csv.text); while (reader.Peek() > -1) { string line = reader.ReadLine(); string[] values = line.Split(','); _timing[i] = float.Parse(values[0]); _lineNum[i] = int.Parse(values[1]); i++; } } float GetMusicTime() { return Time.time - _startTime; } public void GoodTimingFunc(int num) { Debug.Log("Line:" + num + " good!"); Debug.Log(GetMusicTime()); score+= 100; } public void NormalTimingFunc(int num) { Debug.Log("Line:" + num + " nice!"); Debug.Log(GetMusicTime()); score += 50; }
}
//-----------------------------------------
//--------------------リザルト-------------------
using UnityEngine;
using System.Collections;
using System.IO;
using System;
using UnityEngine.UI;
public class ResultScene : MonoBehaviour {
public Text scoreText; // Use this for initialization void Start () { GameObject Score = GameObject.Find("score"); scoreText.text = Score.ToString(); } // Update is called once per frame void Update () { }
}
###試したこと
様々なサイトを閲覧し、DontDestroyOnLoad等々を使ってみたのですが、うまくいきませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
C#でUnityを使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。