LoginSignup
0
0

More than 3 years have passed since last update.

【Unity】制限時間が過ぎたらシーンを遷移させる(自分用)

Posted at

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class test_script : MonoBehaviour
{
    private float counttime = 0.0f;//時間をはかる
    public float timeLimit = 30.0f;//制限時間

    void Start()
    {

    }

    void Update()
    {
        counttime += Time.deltaTime;//マイフレーム事にかかった時間を足している


        if(counttime > timeLimit)
        {
            SceneManager.LoadScene("");//指定した時間が過ぎたらシーン遷移。("")の中に遷移先のシーンの名前をいれる。
        }

    }
}

“shot” 2020-11-06 14.43.01.png

スクリプトを適当なオブジェクトにつけてbuildsettingの中にメインシーンと遷移先のシーンをドラッグドロップで完成。

Time.deltaTimeは最後のフレームを完了するのに要した時間らしい。
それをUpdateの中で足し続けることによって時間を計っている

↓の二つのサイトを参考にした
時間の測り方
シーン遷移

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0