複数ステージ⑥(スコアデータを引き継ぐ)
![114e9b05 e002 4c84 b976 bcaed842ac42](https://codegenius.org/uploads/slide/image/1287/114e9b05-e002-4c84-b976-bcaed842ac42.jpeg)
![36ae08ef 7ebb 4093 ac5b e5df7e4b4b25](https://codegenius.org/uploads/slide/image/1288/36ae08ef-7ebb-4093-ac5b-e5df7e4b4b25.jpeg)
![90e50938 d9c9 4843 bddb 190d8a003348](https://codegenius.org/uploads/slide/image/1289/90e50938-d9c9-4843-bddb-190d8a003348.jpeg)
スコアデータをシーン間で引き継ぐ
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;
}
}
![9abad335 7a5d 4930 bf41 25904e1b5ea0](https://codegenius.org/uploads/slide/image/1290/9abad335-7a5d-4930-bf41-25904e1b5ea0.jpeg)
Danmaku Ⅱ(基礎2/全24回)
他のコースを見る![114e9b05 e002 4c84 b976 bcaed842ac42](https://codegenius.org/uploads/slide/image/1287/114e9b05-e002-4c84-b976-bcaed842ac42.jpeg)
![36ae08ef 7ebb 4093 ac5b e5df7e4b4b25](https://codegenius.org/uploads/slide/image/1288/36ae08ef-7ebb-4093-ac5b-e5df7e4b4b25.jpeg)
![90e50938 d9c9 4843 bddb 190d8a003348](https://codegenius.org/uploads/slide/image/1289/90e50938-d9c9-4843-bddb-190d8a003348.jpeg)
スコアデータをシーン間で引き継ぐ
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;
}
}
![9abad335 7a5d 4930 bf41 25904e1b5ea0](https://codegenius.org/uploads/slide/image/1290/9abad335-7a5d-4930-bf41-25904e1b5ea0.jpeg)
複数ステージ⑥(スコアデータを引き継ぐ)