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 /
  • Help Room /
avatar image
0
Question by McMattGames · Apr 15, 2016 at 05:43 PM · c#crashscene-loadingloadlevel

Application.LoadLevel crashes unity

I was playing with the roll a ball tutorial and was adding more things to it. I wanted to add multiple levels but when I run Application.LoadLevel it crashes. At first it told me to add the scenes to the build settings, so I did. After that it just crashes when I run the game. I tried switching to scenemanager but the import does not work.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class PlayerController : MonoBehaviour
 {
 
     public float speed;
     private int count;
     private Rigidbody rb;
     public Text countText;
     public Text winText;
     public Text loseText;
     public Text hubText1;
     public Image backImage;
     public Button startButton;
 
     public GameObject pickup1;
     public GameObject pickup2;
     public GameObject pickup3;
     public GameObject pickup4;
     public GameObject pickup5;
     public GameObject pickup6;
     public GameObject pickup7;
     public GameObject pickup8;
     public GameObject pickup9;
     public GameObject pickup10;
     public GameObject pickup11;
     public GameObject pickup12;
     public GameObject pickup13;
     public GameObject pickup14;
     public GameObject pickup15;
     public GameObject pickup16;
 
     private bool win;
     private bool StartClicked;
 
     void Start()
     {
 
         Application.LoadLevel("Level1");
         //SceneManagement.SceneManager.LoadScene("Menu_Level"); gives error
         hubText1.gameObject.SetActive(true);
         startButton.gameObject.SetActive(true);
         backImage.gameObject.SetActive(true);
         loseText.gameObject.SetActive(false);
         winText.gameObject.SetActive(false);
         count = 0;
         setCountText();
         rb = GetComponent<Rigidbody>();
         win = false;
         count = 0;
     }
 
     public void startGame()
     {
         count = 0;
         win = false;
         StartClicked = true;
         backImage.gameObject.SetActive(false);
         startButton.gameObject.SetActive(false);
         hubText1.gameObject.SetActive(false);
         rb.gameObject.transform.position = new Vector3(0, 0, 0);
         pickup1.gameObject.SetActive(true);
         pickup2.gameObject.SetActive(true);
         pickup3.gameObject.SetActive(true);
         pickup4.gameObject.SetActive(true);
         pickup5.gameObject.SetActive(true);
         pickup6.gameObject.SetActive(true);
         pickup7.gameObject.SetActive(true);
         pickup8.gameObject.SetActive(true);
         pickup9.gameObject.SetActive(true);
         pickup10.gameObject.SetActive(true);
         pickup11.gameObject.SetActive(true);
         pickup12.gameObject.SetActive(true);
         pickup13.gameObject.SetActive(true);
         pickup14.gameObject.SetActive(true);
         pickup15.gameObject.SetActive(true);
         pickup16.gameObject.SetActive(true);
         rb.isKinematic = false;
         winText.gameObject.SetActive(false);
         loseText.gameObject.SetActive(false);
         countText.text = "Count: " + count;
     }
 
     void FixedUpdate()
     {
         if (win == false) {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         transform.Translate(Input.acceleration.x/10, 0, Input.acceleration.z/10);
 
             rb.AddForce(movement * speed);
         }
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("Pick Up"))
         {
             count += 1;
             other.gameObject.SetActive(false);
            setCountText();
         }
         else
         {
             if (other.gameObject.CompareTag("Danger"))
             {
                 win = true;
                 rb.isKinematic = true;
                 rb.velocity = Vector3.zero;
                 loseText.gameObject.SetActive(true);
                 startButton.gameObject.SetActive(true);
                 backImage.gameObject.SetActive(true);
                 hubText1.gameObject.SetActive(true);
 
             }
         }
     }
 
     void setCountText()
     {
         countText.text = "Count: " + count.ToString();
         if (count >= 16)
         {
             win = true;
             rb.isKinematic = true;
             rb.velocity = Vector3.zero;
             winText.gameObject.SetActive(true);
             startButton.gameObject.SetActive(true);
             backImage.gameObject.SetActive(true);
             hubText1.gameObject.SetActive(true);
 
          //  if (Application.loadedLevel.Equals("Level1")) { 
             //Application.LoadLevel("Level2");
        // }else
        // {
            // if (Application.loadedLevel.Equals("Level2"))
            // {
                 Application.LoadLevel("Minigame");
            // }
        // }
         }
     }  
 }
 
Comment
Add comment · Show 1
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 McMattGames · Apr 15, 2016 at 03:49 PM 0
Share

So I found that this only happens when Application.LoadLevel is used in the start function. Also, when I load a scene it is dark.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save timer score between scenes? (C#) 5 Answers

How to fix Loading Screen? 0 Answers

How do i create a scene variable? 3 Answers

[SOLVED]My code line don't execute 1 Answer

Scene not loading on build but on editor it does. 0 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