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



スコアデータを引き継ぐ
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);
}
}

【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る


スコアデータを引き継ぐ
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);
}
}

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