Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 18, 2018 at 01:14 PM by Gasimo for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by Gasimo · Nov 16, 2016 at 03:45 PM · sceneloadingfile

Load different Scene on first load

Hello everyone! I have got two different scenes: "Normal" scene and "FirstStart" scene. I want to load "FirstStart" on first game startup and "Normal" on every after. (Sorry for english)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

  • Sort: 
avatar image
4
Best Answer

Answer by Desoxi · Nov 17, 2016 at 10:10 AM

Hey @Mpl2014, You dont have to create any text files to check whether or not your app is starting the first time. Just use PlayerPrefs for this and a third scene in which you check stuff like that. This third scene has to be the very first scene in the scene load order inside your build settings. Then you could write something like this and put it inside that start scene.

Assuming you have a scene_01 and scene_02 and a start_scene:

 using UnityEngine;
 using UnityEngine.SceneManagement;
 using System.Collections;
 
 public class StartScene : MonoBehaviour
 {
 
     // Use this for initialization
     void Start()
     {
         if(PlayerPrefs.GetInt("FirstLaunch") == 0)
         {
             //First launch
             PlayerPrefs.SetInt("FirstLaunch", 1);
             SceneManager.LoadScene("scene_01");
         }
         else
         {
             //Load scene_02 if its not the first launch
             SceneManager.LoadScene("scene_02");
         }
     }
 
 }
 

would be the script to put into the start_scene.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by Zodiarc · Nov 16, 2016 at 03:46 PM

You need a scene before those two. In this scene you check for the existence of a file (maybe a save file). If it exists, you proceed with the "Normal" scene. If it not exists, you create it and load the "First start" scene.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gasimo · Nov 17, 2016 at 06:31 AM 0
Share

Great idea but I am still a begginer in scripting. I tried alot of methods in C# but they dont worked so... Did somebody know that script?

avatar image Zodiarc Gasimo · Nov 17, 2016 at 08:37 AM 0
Share

You can use the Directory and File classes in C#. Look here http://answers.unity3d.com/questions/1252963/how-to-check-if-game-was-started-once.html#answer-1252968

avatar image
0

Answer by JeffHardddyyy · Nov 16, 2016 at 05:00 PM

Go to file, build Settings, then drag FirstScene to the top.

Or attack this C# script to a empty object or something

 void Start() {
      Application.LoadLevel("FirstScene");
 }

I'm not home so I don't remember if it's with or without Quotation marks

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aditya007 · Nov 17, 2016 at 10:01 AM 0
Share

This won't do, because it will force the "FirstScene" to load every time application is opened.

avatar image
0

Answer by Gasimo · Nov 17, 2016 at 09:54 AM

If somebody have same question here is answer:

     import System;
     import System.IO;
      
     var  fileName = "MyFile.txt";
      
     function Start()
     {
             if (File.Exists(fileName))
             {
                 Application.LoadLevel("YourLevel2");
                 Debug.Log(fileName+" already exists.");
                 return;
             }
            Application.LoadLevel("YourLevel");
             var sr = File.CreateText(fileName);
             sr.WriteLine ("Your SaveFile Text");
             sr.WriteLine ("You Can write ewerything",
                 1, 4.2);
             sr.Close();
     }
      
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading a saved Game 1 Answer

Editor Crash: Where is Scene Data kept? 3 Answers

Load data from file, if scene changed, fails to load location 0 Answers

how to seperate two visually distinct game modes 1 Answer

Loading Sene problem 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges