Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

I got this this error: "Assets\Movement.cs(18,71): error CS1002: ; expected"

Discussion in 'Scripting' started by Unity-Coder-2020, Oct 26, 2020.

  1. Unity-Coder-2020

    Unity-Coder-2020

    Joined:
    Apr 16, 2020
    Posts:
    3
    Here's my code:
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Movement : MonoBehaviour
    7. {
    8.  
    9.  float speed;
    10.  
    11.  
    12.  private void Start()
    13.  {
    14.     Speed = 5;
    15.  }
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.        trasform.translate(("Horizontal") * Time.deltaTime * Speed,0,0)
    20.     }
    21. }
    EDIT: I have solved all compiler errors in Unity now. Thanks for all the help!
     
    Last edited: Oct 26, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Not all error messages are necessarily easily understood and straightforward, but this one is: You need a semicolon at the end of the line.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You'll have more errors after fixing that semicolon error too. Just writing
    ("Horizontal")
    in the middle of an if statement is a bit like when Michael Scott declared bankruptcy. On its own it's meaningless and out of place. I'm assuming you meant to type something like
    Input.GetAxis("Horizontal")
    there.
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    I didn't look past the semicolon, but yeah good point, there's a bunch of other things. Also "trasform"->"transform", and "translate"->"Translate". You also use inconsistent capitalization for speed/Speed; it can be either, but it has to match.
     
    NOT_A_ROBOT1101 and PraetorBlue like this.
  6. NOT_A_ROBOT1101

    NOT_A_ROBOT1101

    Joined:
    Jun 18, 2020
    Posts:
    39
    I haven't tested, but this might work:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Movement : MonoBehaviour
    6. {
    7.      float speed;
    8.  
    9.      private void Start()
    10.      {
    11.           speed = 5f;
    12.      }
    13.     // Update is called once per frame
    14.      void Update()
    15.      {
    16.           transform.Translate(Time.deltaTime * speed,0,0);
    17.      }
    18. }
     
  7. Unity-Coder-2020

    Unity-Coder-2020

    Joined:
    Apr 16, 2020
    Posts:
    3
    I actually didn't notice that, probably because I don't even know C# and have to google everything, so thanks anyways.
     
  8. HarryPenguin1_

    HarryPenguin1_

    Joined:
    Jun 18, 2022
    Posts:
    1
    i need some help with this am getting error
     
  9. chrische5

    chrische5

    Joined:
    Oct 12, 2015
    Posts:
    52
    Hello

    What error? What Code?

    Christoph
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    Please don't necro post to other peoples ancient threads. It's against forum rules.

    If you're just making typing mistakes, you can fix those yourself. Here's how:

    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.

    The complete error message contains everything you need to know to fix the error 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.