複数ステージ⑥(スコアデータを引き継ぐ)



スコアデータをシーン間で引き継ぐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
// ★変更
//private int score = 0; コメントアウト
// ★追加
// 静的変数(ポイント)
// public staticをつけることで、このScoreManagerスクリプトがついている他のオブジェクトと
// scoreのデータを共有することができるようになります。
// ↓下記の1行を記載する。
public static int score = 0;
private Text scoreLabel;
void Start()
{
scoreLabel = this.gameObject.GetComponent<Text>();
scoreLabel.text = "Score " + score;
}
public void AddScore(int amount)
{
score += amount;
scoreLabel.text = "Score " + score;
}
}

Danmaku Ⅱ(基礎2/全24回)
他のコースを見る


スコアデータをシーン間で引き継ぐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
// ★変更
//private int score = 0; コメントアウト
// ★追加
// 静的変数(ポイント)
// public staticをつけることで、このScoreManagerスクリプトがついている他のオブジェクトと
// scoreのデータを共有することができるようになります。
// ↓下記の1行を記載する。
public static int score = 0;
private Text scoreLabel;
void Start()
{
scoreLabel = this.gameObject.GetComponent<Text>();
scoreLabel.text = "Score " + score;
}
public void AddScore(int amount)
{
score += amount;
scoreLabel.text = "Score " + score;
}
}

複数ステージ⑥(スコアデータを引き継ぐ)