My code:
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
bool gameHasEnded = false;
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Invoke(“Restart”, 1f);
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
It claims that “The local function ‘Restart’ is declared but not used.” I dont know why this is happening but it is happening.
USE CODE TAGS:
If you see someone who needs to know about code tags, please link them to this post:
Please use code tags when posting code.
You can "tag" your code by typing [984347--130826--Screenshot 2015-03-16 10.33.58.png] around your code.
There is no overt "Code" tag button that automatically tags a selection as code.
That being said, however, we can Insert code directly into the post using the "Insert Code" button:
[image]
This will bring up an "Insert" window were we can paste our code and c…
Formatted for you:
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
bool gameHasEnded = false;
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Invoke("Restart", 1f);
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
I don’t even see how this code compiles… you have your Restart method defined inside your EndGame method.
Sorry to break it to you, but you script didnt work, but with the info you provided I managed to fix it.
Vryken
June 21, 2019, 9:12pm
4
lordofduct:
USE CODE TAGS:
https://discussions.unity.com/t/481379
Formatted for you:
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
bool gameHasEnded = false;
public void EndGame ()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Invoke("Restart", 1f);
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
I don’t even see how this code compiles… you have your Restart method defined inside your EndGame method.
Unity now supports C# 7 and up, which added the ability to create local methods.
Yeah… my script didn’t work because IT WAS YOUR SCRIPT.
I didn’t edit it… I just added the code tags so it became readable on the forum.
Do you not recognize your own damn code?
Aw, yeah I haven’t been on latest version of Unity using C#7 features… been version locked for a while now.
…
Back at OP, this would explain the problem though. a local function is not a member function of GameManager, where as Invoke only works on member functions.
I think someone accidentally used .Provoke() instead of .Invoke()…
.Provoke() is part of the Anger Driven Development framework.
5 Likes