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

Bug Please someone who knows how to code tell me how to resolve this bug

Discussion in 'Scripting' started by MrDiscoWhale, Mar 30, 2022.

  1. MrDiscoWhale

    MrDiscoWhale

    Joined:
    Mar 29, 2022
    Posts:
    1
    The bug is
    Assets\Scripts\PlayerMove.cs(20,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations
    as soon as i drag any C# code into an object (ex. cube) it crashes my game
    Please help
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    How are we supposed to help without seeing your code?
    Have you configured your code editor so that it shows errors inline?
    The error is implying you have a using clause somewhere besides the top of the file, which is the only place they should be.
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,513
    What does PlayerMove.cs have in it?

    I'm betting at line 20 you have a using statement that follows some other element definition (like the class or something).

    Likely something like this:

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class MyScript : MonoBehaviour
    4. {
    5.  
    6.     public int Value;
    7.     public string SValue;
    8.  
    9.     using UnityEngine.UI;
    10.  
    11.     void Start() { }
    12.  
    13. }
    ...

    Post your code for PlayerMove.cs and we will be able to be more specific.

    Or... as I said, it's at line 20, as your error states. Go to line 20 in PlayerMove.cs and you'll find your problem.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    That's not a bug, that's YOUR TYPO.

    Here's how you can fix YOUR TYPO.

    It does not require anyone here to fix YOUR TYPO.

    The complete error message contains everything you need to know to fix YOUR TYPO by yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.