複数ステージ③(ステージクリアー)
ScoreManagerの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// ★追加
using UnityEngine.SceneManagement;
public class ScoreManager : MonoBehaviour
{
private 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回)
他のコースを見るScoreManagerの改良
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// ★追加
using UnityEngine.SceneManagement;
public class ScoreManager : MonoBehaviour
{
private 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);
}
}
複数ステージ③(ステージクリアー)