複数ステージ④(スコアデータを引き継ぐ)
![0fe334d9 7c63 4d98 9b16 36e85b5f4813](https://codegenius.org/uploads/slide/image/4886/0fe334d9-7c63-4d98-9b16-36e85b5f4813.jpeg)
![Cbfc2176 3e23 4cbd 96f8 5b542efae210](https://codegenius.org/uploads/slide/image/4887/cbfc2176-3e23-4cbd-96f8-5b542efae210.jpeg)
![7da0f8f0 ce63 43e7 bac9 21b366820e44](https://codegenius.org/uploads/slide/image/4888/7da0f8f0-ce63-43e7-bac9-21b366820e44.jpeg)
スコアデータを引き継ぐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ScoreManager : MonoBehaviour
{
// ★修正
// 静的変数(ポイント)
// public staticをつけることで、このScoreManagerスクリプトがついている他のオブジェクトと
// scoreのデータを共有することができるようになります。
public static int score = 0;
private Text scoreLabel;
public AudioClip clearSound;
public int clearScore;
public string nextStageName;
private bool isClear = false;
void Start()
{
scoreLabel = GetComponent<Text>();
scoreLabel.text = "SCORE:" + score;
}
public void AddScore(int amount)
{
score += amount;
scoreLabel.text = "SCORE:" + score;
if(score > clearScore && !isClear)
{
AudioSource.PlayClipAtPoint(clearSound, Camera.main.transform.position);
isClear = true;
Invoke("StageClear", 1.0f);
}
}
void StageClear()
{
SceneManager.LoadScene(nextStageName);
}
}
![5d73b0a1 90dc 4e11 8a81 e3f7e69ad113](https://codegenius.org/uploads/slide/image/4889/5d73b0a1-90dc-4e11-8a81-e3f7e69ad113.jpeg)
【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る![0fe334d9 7c63 4d98 9b16 36e85b5f4813](https://codegenius.org/uploads/slide/image/4886/0fe334d9-7c63-4d98-9b16-36e85b5f4813.jpeg)
![Cbfc2176 3e23 4cbd 96f8 5b542efae210](https://codegenius.org/uploads/slide/image/4887/cbfc2176-3e23-4cbd-96f8-5b542efae210.jpeg)
![7da0f8f0 ce63 43e7 bac9 21b366820e44](https://codegenius.org/uploads/slide/image/4888/7da0f8f0-ce63-43e7-bac9-21b366820e44.jpeg)
スコアデータを引き継ぐ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ScoreManager : MonoBehaviour
{
// ★修正
// 静的変数(ポイント)
// public staticをつけることで、このScoreManagerスクリプトがついている他のオブジェクトと
// scoreのデータを共有することができるようになります。
public static int score = 0;
private Text scoreLabel;
public AudioClip clearSound;
public int clearScore;
public string nextStageName;
private bool isClear = false;
void Start()
{
scoreLabel = GetComponent<Text>();
scoreLabel.text = "SCORE:" + score;
}
public void AddScore(int amount)
{
score += amount;
scoreLabel.text = "SCORE:" + score;
if(score > clearScore && !isClear)
{
AudioSource.PlayClipAtPoint(clearSound, Camera.main.transform.position);
isClear = true;
Invoke("StageClear", 1.0f);
}
}
void StageClear()
{
SceneManager.LoadScene(nextStageName);
}
}
![5d73b0a1 90dc 4e11 8a81 e3f7e69ad113](https://codegenius.org/uploads/slide/image/4889/5d73b0a1-90dc-4e11-8a81-e3f7e69ad113.jpeg)
複数ステージ④(スコアデータを引き継ぐ)