ゲームクリアーシーン②(スコアデータの引き継ぎと表示)



シーン間でスコアデータを引き継ぐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour
{
public TextMeshProUGUI scoreLabel;
// ★改良
// 「static」キーワードを追加する(ポイント)
// これでシーン間でスコアデータを引き継げるようになる。
private static int score;
void Start()
{
scoreLabel.text = "" + score.ToString("D15");
}
public void AddScore(int amount)
{
score += amount;
scoreLabel.text = "" + score.ToString("D15");
}
}


【2021版】Danmaku(基礎/全55回)
他のコースを見る


シーン間でスコアデータを引き継ぐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ScoreManager : MonoBehaviour
{
public TextMeshProUGUI scoreLabel;
// ★改良
// 「static」キーワードを追加する(ポイント)
// これでシーン間でスコアデータを引き継げるようになる。
private static int score;
void Start()
{
scoreLabel.text = "" + score.ToString("D15");
}
public void AddScore(int amount)
{
score += amount;
scoreLabel.text = "" + score.ToString("D15");
}
}


ゲームクリアーシーン②(スコアデータの引き継ぎと表示)