LoginSignup
7
12

More than 5 years have passed since last update.

【Unity】Application.LoadLevelは非推奨になっていました

Last updated at Posted at 2019-03-25

背景

Unity5 3D/2Dゲーム開発 実践入門 作りながら覚えるスマートフォンゲーム制作(吉谷 幹人) | 書籍 本 | ソシムの本に書いあるコードを写経していたら、他のシーンを呼び出すApplication.LoadLevelは非推奨ですと警告されました。

loadlevel.png

修正案

Visual Studioが親切に、UseSceneManager.LoadSceneと教えてくれたので、言われた通りに修正すると、想定どおりに「ゲームタイトルのシーン⇔メインゲームのシーン」に遷移できました。

loadscene.png

終わりに

どうやらUnity 5.3(2015年12月16日リリース)の頃から、Application.LoadLevel が非推奨になったようです。
自分がギリギリUnityを触ってた頃だったのですが、知らなかったので記事にしました。

他にも、自分が過去に使っていたApplication.LoadLevelAdditive(遷移前のシーンを残して、他のシーンを呼び出す)も非推奨になっていました。
同じくApplication.LoadLevelを使用すると、警告は消えます。

まとめると、下のような感じです。

        // 他のシーンを呼び出す
        Application.LoadLevel("Main"); // 非推奨
        SceneManager.LoadScene("Main"); // OK

        // 遷移前のシーンを残して、他のシーンを呼び出す
        Application.LoadLevelAdditive("Main"); // 非推奨
        SceneManager.LoadScene("Main", LoadSceneMode.Additive); // OK

        // 現在読み込んでいるシーンを再読込
        Application.LoadLevel(Application.loadedLevel); // 非推奨
        SceneManager.LoadScene(SceneManager.GetActiveScene().name); // OK
7
12
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
7
12