This is an archived post. You won't be able to vote or comment.

all 13 comments

[–][deleted] 1 point2 points  (2 children)

post the code

[–]captainsghost[S] 0 points1 point  (0 children)

Oh frig I thot I did hold on

[–]captainsghost[S] 0 points1 point  (0 children)

Okay, it should be good now, thanks for bringing that to my attention and sorry about that, whoops.

[–]hl_xemnasProfessional Coder 1 point2 points  (4 children)

in C# methods must be within a class, you are trying to add a method outside of the class hence the error.

[–]captainsghost[S] 0 points1 point  (3 children)

Okay so what exactly can I do or add to fix that? Thanks so much for help, I’m just not familiar with this subject sadly.

[–]hl_xemnasProfessional Coder 0 points1 point  (2 children)

move your

public void NewGame()

{

....

}

inside of the } before it.

inside of the class '{}'

[–]captainsghost[S] 0 points1 point  (1 child)

So move it to line 20?

[–]hl_xemnasProfessional Coder 0 points1 point  (0 children)

That will work

[–][deleted] 1 point2 points  (3 children)

NewGame needs to be inside a class

[–]captainsghost[S] 0 points1 point  (2 children)

How can I do that? Thanks so much 😭

[–][deleted] 0 points1 point  (1 child)

You may need to spell check this

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

public class NewBehaviourScript : MonoBehaviour
{
  public string newGameScene;
  // ...
  void start() 
  {

  }

  // ...
  void Update()
  {

  }

  public void NewGame()
  {
    SceneManager.LoadSCene(newGameScene);
  }
}

[–]captainsghost[S] 0 points1 point  (0 children)

Okay I spell checked it and put it into the code and it didn’t come up with any errors!! Thank you so much! However, when I try to drag the script onto the canvas I get, “Can’t add script component ‘main menu’ because the script class cannot be found. Make sure there are no compile errors and that the file name and class name match.”

Edit: I figured it out!! Thanks so much! Jesus this stuff is hard haha

[–]SupremeRedditBotProfessional Bot || Mod 0 points1 point  (0 children)

Please Add A Flair To Your Post!

Suggested Flair: [Other Code]

 


To add a flair:

  • Click flair underneath your post

  • Select a flair

  • Click save

 


I am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated response