Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I need help with some basic code

Discussion in 'Scripting' started by ColeoCraft, Jun 7, 2017.

  1. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    Code (CSHARP):
    1.  
    2. im using C# monodevelop-unity and I was watching a video on how to make a basic game and
    3. some of his code don't work on my game but he is using VisualStudio would that change anything every other code that he did worked on monodevelop but not this one
    4.  
    5. Code:
    6.  
    7. using UnityEngine;
    8. using UnityEngine.SceneManagement;
    9.  
    10.  
    11. public class GameManager : MonoBehaviour {
    12.  
    13. bool gameHasEnded = false;
    14.  
    15. public void EndGame ()
    16. {
    17. if (gameHasEnded == false)
    18. {
    19. gameHasEnded = true;
    20. Debug.Log ("Game Over");
    21. // Restarting game
    22. }
    23. }
    24.  
    25. void Restart ();
    26. {
    27. SceneManager.LoadScene.(SceneManager.GetActiveScene().name);
    28. }
    29.  
    30. }
     
    Last edited: Jun 7, 2017
  2. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    First off, please take a look at this thread and then put your code in code tags: https://forum.unity3d.com/threads/using-code-tags-properly.143875/

    Secondly, it shouldn't make a difference no. One thing I'll point out is this part:
    Code (csharp):
    1.  
    2. SceneManager.Load(SceneManager.().name);
    3.  
    Not sure what you were attempting to type here, but "SceneManager.().name" is not correct. Verify what the tutorial video said you should type in there. Anyways, fixing that might fix whatever your issue is... but if not, you need to actually tell us what your issue is, including any errors you may be receiving.
     
  3. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    oops i did it wrong i deleted some stuff to see if it worked here is the accually part that i was trying to write

    ScenceManager.LoadScene(SceneManager.GetActiveScene().name);

    here is the link to the video:


    the time should be somewhere in between 8:40 and 8:50
     
  4. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    I don't really understand code yet i just started yesterday so I don't get what he's trying to do in the link that u sent me
     
  5. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    Code (CSHARP):
    1.  
    2. and when im typing code you know how it shows you what your options are for some code like if i put Debug. and it would show up a suggestion for Debug.Log it dosn't show the suggestions for  ScenceManager.LoadScene(SceneManager.GetActiveScene().name); so im not sure if its monodevelop and I was told that monodevelop was for mac is that true because im on windows[/COLOR]
     
    Last edited: Jun 7, 2017
  6. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    The link I sent was so that you can paste code HERE and have it look like how I pasted coded in my paste (which is formatted, highlighted, and a lot easier for everyone else to read).

    I'm not clear from your 2nd post though if you're still having a problem now that you found the error, but if you are, please tell us what's happening now (errors?? if so, what?)
     
  7. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    I use MonoDevelop on Windows. I think a lot of people prefer something else, but I really like it for Unity, myself.

    Typing "Scenemanager." should bring up some suggestions in MonoDevelop too, I think.. if not, I wonder if you're using an older version of Unity? The SceneManagement class is new as of 5.3
     
  8. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    i made a video on it and ill show you
     
  9. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    never mind it didnt work
     
  10. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    this is the error 1
    Assets/Scripts/GameManager.cs(20,2): error CS9010: Primary constructor body is not allowed
    and error 2
    Assets/Scripts/GameManager.cs(21,25): error CS1001: Unexpected symbol `(', expecting identifier
     
  11. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    That post I mentioned earlier on using code tags , you really need to do this, as when you don't, it makes it a lot harder on anyone to understand code you've posted. The link tells you exactly how and why to use code tags.. it's pretty simple. Please read that link first, and, using "code tags", paste your code you have now after having fixed the initial typo I've pointed out.
     
  12. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    Code (CSHARP):
    1.  
    2.  
    3. Assets/Scripts/GameManager.cs(21,25): error CS1001: Unexpected symbol `(', expecting identifier
    4.  
    5. Assets/Scripts/GameManager.cs(20,2): error CS9010: Primary constructor body is not allowed
     
  13. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    haha, no, not your error in code tags.. your code.. i.e. the stuff in post 1, but with your recent changes. At least you used code tags this time though :)
     
  14. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    oh ok lol
     
  15. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    im using unity 5.6.1f1
     
  16. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Are you going to paste your latest code here (Again, use the code tags for that.. code tags are for making code more easily readable here).
     
  17. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    and i changed the code in post 1 and corrected it and moved it down here
     
  18. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    Code (CSHARP):
    1.  
    2. im using C# monodevelop-unity and I was watching a video on how to make a basic game and
    3. some of his code don't work on my game but he is using VisualStudio would that change anything every other code that he did worked on monodevelop but not this one
    4.  
    5. Code:
    6.  
    7. using UnityEngine;
    8. using UnityEngine.SceneManagement;
    9.  
    10.  
    11. public class GameManager : MonoBehaviour {
    12.  
    13. bool gameHasEnded = false;
    14.  
    15. public void EndGame ()
    16. {
    17. if (gameHasEnded == false)
    18. {
    19. gameHasEnded = true;
    20. Debug.Log ("Game Over");
    21. // Restarting game
    22. }
    23. }
    24.  
    25. void Restart ();
    26. {
    27. SceneManager.LoadScene.(SceneManager.GetActiveScene().name);
    28. }
    29.  
    30. }
     
  19. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Oh man.. you're killing me here. lol So code tags are for code, and only code.. you put your code in between the code tags (thus why they're called code tags), everything else outside of the code tags. But it's all good, as I can see your error is here:

    Code (csharp):
    1. SceneManager.LoadScene.(SceneManager.GetActiveScene().name);
    It should be:

    Code (csharp):
    1. SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    You need to have a lot more attention to detail when coding.. type exactly what the video says. Anyways, correct the line above with my code, and I think you should be good.
     
  20. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    oh ty ill see if that worked
     
  21. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    it still shows an error
     
  22. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    this one still but the other one is gone

    Assets/Scripts/GameManager.cs(20,2): error CS9010: Primary constructor body is not allowed
     
  23. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Ok that's because you have a semicolon ( ; ) after Restart()... delete the semicolon.

    Code (csharp):
    1.  
    2. void Restart ()
    3. {
    4.     SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    5. }
     
  24. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    that fixed that one but now it shows this one lol

    ssets/Scripts/GameManager.cs(21,16): error CS0117: `UnityEngine.SceneManagement.SceneManager' does not contain a definition for `loadScene'
     
  25. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    remove the semicolon after Restart()
     
  26. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    C# is Case-Sensitive it should be LoadScene
     
  27. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    it's LoadScene, not loadScene..

    again, attention to detail...
     
  28. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    i did remove the semicolon but now it shows an new one

    Code (csharp):
    1.  
    2. Assets/Scripts/GameManager.cs(21,16): error CS0117: `UnityEngine.SceneManagement.SceneManager' does not contain a definition for `loadScene'
     
  29. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    that fixed that one now there is a new one lol

    Assets/Scripts/GameManager.cs(21,39): error CS0117: `UnityEngine.SceneManagement.SceneManager' does not contain a definition for `GetAvtiveScene'
     
  30. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    nvm I found this one now it works ty
     
  31. ColeoCraft

    ColeoCraft

    Joined:
    Jun 7, 2017
    Posts:
    30
    i spelled another thing wrong GetAvtiveScene instead its suppost to be GetActiveScene
     
  32. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    So now you've learned that coding isn't about typing 85% of the code correctly, right? :D

    Glad it works for you now.
     
  33. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    This guy/thread was cracking me up! lol Glad you got it solved.

    Good luck with coding.. and code tags!! :)