Facing some errors with Unity new updates, Need HELP!!

Updated on April 22, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
3 on April 21, 2017

I’m using unity engine 5.4 and here’s the script for my pause menu.
I know Unity changed some ways of writing code, Please correct any if there.

I’m complete noob with unity coding, this is my crappy coding.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Pause : MonoBehaviour {

GameObject Pausemenu;
bool paused;
bool muted;
[SerializeField]
Text mutetext;

// Use this for initialization
void Start () {
paused = false;
Pausemenu = GameObject.Find (“Pausemenu”);
}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {

paused = !paused;

}

if (paused) {

Pausemenu.SetActive (true);
Time.timeScale = 0;

}

else if (!paused)

{

Pausemenu.SetActive (false);
Time.timeScale = 1;
}

if (muted)
{

AudioListener.volume = 0;
mutetext.text = “unmute”;
} else if (!muted){

AudioListener.volume = 1;
mutetext.text = “mute”;
}
}

public void Resume()
{paused = false;
}

public void Mainmenu()
{Application.LoadLevel (2);
}

public void Save()
{

PlayerPrefs.SetInt (“currentscenesave”.Application.loadedlevel);
}

public void load()
{
Application.LoadLevel(PlayerPrefs.GetInt(“currentscenesave”));
}

public void Mute()
{
muted = !muted;
}

public void Quit()
{

Application.Quit ();
}

}

There are some new features like unity scene manager, I don’t know how to use.

  • Liked by
Reply
0 on April 21, 2017

What errors? …. we aren’t magicians here

  • Liked by
Reply
Cancel
0 on April 22, 2017

The namespace `global::’ already contains a definition for `Pause’
This is the error I’m getting

  • Liked by
Reply
Cancel
0 on April 22, 2017

I fixed myself, just getting this error in main menu (coding which is in bold letters)

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;

public class Possing : MonoBehaviour {

GameObject Pausemenu;
bool paused;
bool muted;
[SerializeField]
Text mutetext;

// Use this for initialization
void Start () {
paused = false;
Pausemenu = GameObject.Find (“Pausemenu”);
}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {

paused = !paused;

}

if (paused) {

Pausemenu.SetActive (true);
Time.timeScale = 0;

}

else if (!paused)

{

Pausemenu.SetActive (false);
Time.timeScale = 1;
}

if (muted)
{

AudioListener.volume = 0;
mutetext.text = “unmute”;
} else if (!muted){

AudioListener.volume = 1;
mutetext.text = “mute”;
}
}

public void Resume()
{paused = false;
}

public void Mainmenu()
{
SceneManager.GetActiveScene(2).buildIndex;
}

public void Save()
{

PlayerPrefs.SetInt (“currentscenesave”,SceneManager.GetActiveScene().buildIndex);
}

public void load()
{
SceneManager.LoadScene(PlayerPrefs.GetInt(“currentscenesave”));
}

public void Mute()
{
muted = !muted;
}

public void Quit()
{

Application.Quit ();
}

}

Error msg says
Only assignment, call, increment, decrement, and new object expressions can be used as a statement

  • Liked by
Reply
Cancel