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 $$anonymous$$ · Dec 16, 2015 at 12:03 PM · scripting problemupdatehealthbar

Application.LoadLevel Obsolete? Nothing Suggested works

Its pretty much like the question states.

Scene Manager does not work.

This is from the tutorial by Pix Labs for making a health bar function as shown here at .https://www.youtube.com/watch?v=fkUpXpD5PRs.

It goes like this.

 public class HealthControl : MonoBehaviour
 {
     public Image healthBar;
     public float health;
     public GameObject restartDialog;
     
 
     void Start()
     {
         ShowRestartDialog(false);
     }
     void Update()
     {
         checkHealth();
     }
     void checkHealth()
     {
         healthBar.rectTransform.localScale = new Vector3(health / 100, healthBar.rectTransform.localScale.y, healthBar.rectTransform.localScale.z);
         if (health <= 0.0f)
         {
             ShowRestartDialog(true);
         }
     }
     void OnCollisionEnter(Collision other)
     {
         if (other.collider.CompareTag("Death"))
         {
             SubtractHealth(30.0f);
         }
         else if (other.collider.CompareTag("Life"))
         {
             AddHealth(30.0f);
         }
     }
     public void SubtractHealth(float amount)
     {
         if (health - amount < 0.0f)
         {
             health = 0.0f;
         }
         else
         {
             health -= amount;
         }
     }
     public void AddHealth(float amount)
     {
         if (health + amount > 100.0f)
         {
             health = 100.0f;
         }
         else
         {
             health += amount;
         }
     }
     public void ShowRestartDialog(bool c)
     {
         if (c)
         {
             Time.timeScale = 0.0f;
         }
         else
         {
             Time.timeScale = 1.0f;
         }
         restartDialog.SetActive(c);
     }
     public void Restart()
     {
         Application.LoadLevel(Application.loadedLevel);
     }
 }

Then Unity says this:

 Assets/Scripts/HealthControl.cs(76,43): warning CS0618: `UnityEngine.Application.loadedLevel' is obsolete: `Use SceneManager to determine what scenes have been loaded'
 

So the revision attempted went like this

  SceneManager.LoadScene(index);

It did not work.

Adding the other suggestion given from the editor as in adding the additional

using UnityEngine.SceneManagement;

Did nothing at all to make the code work.

The only modification I did was change the Tag to be found from LIFE to Life and ENEMY to Death and made sure the tags on the said objects had the same tag spellings. In any cause the last line of code with application manager isn't working at all and the "solutions" are non-existent.

Help would be appreciated and I can in turn if there is one send the notice to Pix Labs and others having similar issues with tutorials not functioning in the latest Unity released update.

Comment
Add comment · Show 2
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 mikelortega · Dec 16, 2015 at 12:36 PM 1
Share

I still have not tried 5.3, but I would try something like this:

 Application.LoadLevel(Scene$$anonymous$$anager.GetActiveScene().buildIndex);
avatar image $$anonymous$$ mikelortega · Dec 16, 2015 at 10:47 PM 0
Share

Tried it but no cigar. TY though.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SVER · Dec 17, 2015 at 07:45 AM

I had this same issue, it was because I had a custom script already with the name SceneManager. If you do as well Unity will access this every time even if you've already imported SceneManagement...

To see if you can access it try accessing it using the full address in your code, it will call Unity's SceneManager regardless of whether or not you've imported it at the beginning of your script.

Just typing the line below won't be enough (at least it wasn't for me), even if you've imported unity's SceneManager correctly:

 SceneManagement.SceneManager.LoadScene("scene_name");

Instead, for every reference try:

 UnityEngine.SceneManagement.SceneManager

Here's an example of what ended up working for me:

     public void RestartLevel()
     {
         Debug.Log("restart function called");
 
 //        Application.LoadLevel(Application.loadedLevel);            //old function
         UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex);
     }

Obviously you don't want to type out the full address every time, so you'll probably want to create a shortcut or change YOUR SceneManager script name completely.

Hope this helps!

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 $$anonymous$$ · Jan 18, 2016 at 08:01 AM 0
Share

Yeah i found out the specific on this one at least.

You only do Scene$$anonymous$$anager.LoadScene("scene_name");

if you are doing a startup like from a main menu going to the first level.

Then when wanting to load what current level you are in such as restarting that scene or level you set it as;

Scene$$anonymous$$anager.LoadScene(PlayerPrefs.GetInt("currentscenesave"));

rather than : Application.LoadLevel(Application.loadedLevel);

or alternatively 'Scene$$anonymous$$anager.LoadScene (Scene$$anonymous$$anager.GetActiveScene().buildIndex); .

rather than :

Application.LoadLevel(Scene$$anonymous$$anager.GetActiveScene().buildIndex); which is an erroneous combination of code because its attempting to combine Application with Scene$$anonymous$$anager, blah, blah blah.

avatar image
0

Answer by Jessespike · Dec 16, 2015 at 07:20 PM

 using UnityEngine.SceneManagement;

Or you can call SceneManager like this:

 SceneManagement.SceneManager.LoadScene("foo");

http://answers.unity3d.com/questions/1113197/applicationloadlevel-obsolete-but-scenemanagerload.html

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 $$anonymous$$ · Dec 16, 2015 at 10:18 PM 0
Share
 Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene("foo");? 

I thought that was "fool" LOL and i tried it anyways. but no luck yet and still tryin.

avatar image
0

Answer by $$anonymous$$ · Dec 16, 2015 at 10:53 PM

So I tried this; and if i set the health down manually to zero even though everything is in place, the tags of the targets ans script on the player, and the UI plugged into the script, still no collision detection to cause a reaction. Sure it acts solid like its suppose to (the life and death objects), but no reaction from the UI.

This revision I made also now shows no errors but still isn't functioning.

 using UnityEngine;
     using UnityEngine.UI;
     using UnityEngine.SceneManagement;
     using System.Collections;
 
 
 public class HealthControl : MonoBehaviour
 {
     public Image healthBar;
     public float health;
     public GameObject restartDialog;
     
 
     void Start()
     {
         ShowRestartDialog(false);
     }
     void Update()
     {
         checkHealth();
     }
     void checkHealth()
     {
         healthBar.rectTransform.localScale = new Vector3(health / 100, healthBar.rectTransform.localScale.y, healthBar.rectTransform.localScale.z);
         if (health <= 0.0f)
         {
             ShowRestartDialog(true);
         }
     }
     void OnCollisionEnter(Collision other)
     {
         if (other.collider.CompareTag("Death"))
         {
             SubtractHealth(30.0f);
         }
         else if (other.collider.CompareTag("Life"))
         {
             AddHealth(30.0f);
         }
     }
     public void SubtractHealth(float amount)
     {
         if (health - amount < 0.0f)
         {
             health = 0.0f;
         }
         else
         {
             health -= amount;
         }
     }
     public void AddHealth(float amount)
     {
         if (health + amount > 100.0f)
         {
             health = 100.0f;
         }
         else
         {
             health += amount;
         }
     }
     public void ShowRestartDialog(bool c)
     {
         if (c)
         {
             Time.timeScale = 0.0f;
         }
         else
         {
             Time.timeScale = 1.0f;
         }
         restartDialog.SetActive(c);
     }
     public void Restart()
     {
         SceneManager.LoadScene("loadScene");
     }
 }

Ready to snatch myself bald. lol.

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 $$anonymous$$ · Dec 16, 2015 at 10:55 PM 0
Share

P.S. I have no changed character collider to character controller for better physics, but it still is not detecting any collisions in the UI. Its detecting collision with normal movement just fine.

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

34 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

Related Questions

Picked up items being added multiple times on the inventory list. 1 Answer

Just updated to newest Unity version but something's missing 0 Answers

Health script 0 Answers

Slow down animation with constantly pressing mouse,I have to keep pressing the mouse to slow the animation BlendSpeed. 0 Answers

Start() and Update() execution issue 6 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