UnityでFPSをつくる その10-8 [ シーン遷移 ]
前回までで、ClearSceneからTitleSceneへの遷移が完成しました。
今回はGameOverSceneからTitleSceneへの遷移を実装していきます。

といっても、やることは同じです。
GameOverシーンへ切り替え、スクリプトを「ToTitleSceneFromGameOver」の名前で新規作成します。

そこに、以下のコードを貼り付けます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class ToTitleSceneFromGameOver : MonoBehaviour
{
[SerializeField] Image switchingEffect;
float elapsedTime;
float heightNum;
const int maxWidth = 1920, maxHeight = 1080;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
elapsedTime += Time.deltaTime;
if (elapsedTime > 5.0f)
{
if (switchingEffect.rectTransform.sizeDelta.y < maxHeight)
{
heightNum = Mathf.Pow(heightNum + 1.1f, 1.1f);
switchingEffect.rectTransform.sizeDelta = new Vector2(maxWidth, heightNum);
}
else
{
switchingEffect.rectTransform.sizeDelta = new Vector2(maxWidth, maxHeight);
Invoke("ToTitleScene", 1f);
}
}
}
void ToTitleScene()
{
SceneManager.LoadScene("TitleScene");
}
}
内容はGameClearの時と同じです、スクリプト名だけ変更しています。
以降の手順もGameClearの時と同じです。
実行して結果を見てみましょう。

TitleSceneへ遷移できました。
これで[シーン遷移]の項目は終了となります、おつかれさまでした!