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 /
avatar image
0
Question by maniraj06 · Aug 13, 2017 at 05:35 AM · application.loadlevel

need an updated command for application.loadlevel for unity 5.5 version

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class GameManager : MonoBehaviour {

 public static int currentScore;
 public static int highScore;

 public static int currentLevel= 0;
 public static int unlockedLevel;

 public static void CompleteLevel()
 {
     if (currentLevel < 2) {
         currentLevel++;
         Application.LoadLevel(currentLevel);
     } else {
         print ("you win");
     }
 }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Arylos · Aug 13, 2017 at 06:18 AM

Application.LoadLevel() has been deprecated since (I think) 5.2. You use SceneManager now so change your code to the following.

 using System.Collections; 
 using System.Collections.Generic; 
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour 
 {
      public static int currentScore;
      public static int highScore;
      public static int currentLevel= 0;
      public static int unlockedLevel;

      public static void CompleteLevel()
      {
           if (currentLevel < 2) {
               currentLevel++;
               SceneManager.LoadScene(currentLevel);
      } 
      else 
      {
          print ("you win");
      }
  }

 

Refer to the SceneManager documentation: C# Scripting API: SceneManager

Also, I forgot a bracket in my code so don't forget to add a final bracket at the end!

The most preferred way to reload the current level is to actually remove the variable currentLevel and replace the function with SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);, although that's a preference by me so that way I don't have an extra variable and the code automatically works on any level application.

Comment
Add comment · Show 3 · 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 Arylos · Aug 13, 2017 at 06:19 AM 0
Share

Also, I missed a bracket in my code so don't forget to add that!

avatar image maniraj06 · Aug 13, 2017 at 06:39 AM 0
Share

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour {

 public float moveSpeed;
 private float maxSpeed=5f;
 private Vector3 input;
 private Vector3 spawn;
 public GameObject deathParticles;


 // Use this for initialization
 void Start () {
     spawn = transform.position;

 }

 // Update is called once per frame
 void Update () {

     input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
     if (GetComponent<Rigidbody> ().velocity.magnitude < maxSpeed) {
         GetComponent<Rigidbody> ().AddForce (input * moveSpeed);
     }

     if (transform.position.y < 0.5) {
         die();
     }
 }

 void OnCollisionEnter(Collision other)
 {
     
     if (other.transform.tag == "enemy") {
         die();
     }
 }

 void onTriggerEnter(Collider other)
 {
     if (other.transform.tag == "goal") {
         Game$$anonymous$$anager.CompleteLevel();
     }
     
 }

 void die()
 {
     Instantiate (deathParticles, transform.position, Quaternion.identity);
     transform.position = spawn;
 }

}

can u relate this code with the above one... my player when hits the goal,it does nothing.the isTrigger is checked. can u plz send the correct code for my game to go to the next level

avatar image Arylos · Aug 13, 2017 at 06:57 AM 0
Share

If it's a 2D game, then it's not the issue with your code, which is what I see so far. You may need to change how your physics interact with each other. This is a complex issue based on how your physics is setup.

You might need to refer to the Box Collider documentation as it has a helpful chart that's useful in seeing if messages are being sent or not at the bottom. So, if your player has a static trigger collider, you will need to add a rigidbody to your enemies, and vice versa. Playing with those cause different effects (rigidbodies obey gravity and will start "falling" while kinematic rigidbodies don't obey gravity, but only move when you specify them too. $$anonymous$$inematics are helpful for player controllers).

Overall, it just depends on what colliders you have set up. I recommend referring to that chart to see what you need to do to the individual elements.

avatar image
0

Answer by tanoshimi · Aug 13, 2017 at 06:28 AM

Surprised that you didn't get a message about this, but you need to use the SceneManager class instead:

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

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

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

68 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

Related Questions

Application.LoadLevel not working on iOS 2 Answers

How can i hide a gameobject ? 1 Answer

How to load Level using scene object?? 2 Answers

Don't lose variable data when reloading a level - c# 3 Answers

Application.LoadLevel, Send me to the same Scene 5 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