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 .How To Make A Health Bar In Unity 5 - Tutorial Tuesdays - PixLab - YouTube.

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.

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

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.

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!