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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

are there any errors in my script for move player ?

Discussion in 'Scripting' started by Teamcipo, May 12, 2020.

  1. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    my script for move:

    using UnityEngine;

    public class PlayerMouvement : MonoBehaviour
    {
    public float MoveSpeed;

    public Rigidbody2D rb;
    private Vector3 velocity = Vector3.zero;

    void Update()
    {
    float horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;

    MovePlayer(horizontalMouvement)
    }

    void MovePlayer(float _horizentalMouvement)
    {
    Vector3 targetVelocity = new Vector2 (_horizentalMouvement, rb.velocity.y);
    rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity,05f)
    }
    }
     
  2. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    Pls help me
     
  3. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    and i am in Visual Studio Code
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Instead of spamming, could format your code and edit your post to contain a proper question.
     
  5. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
  6. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10

    using UnityEngine;

    public class PlayerMouvement : MonoBehaviour
    {
    public float MoveSpeed;

    public Rigidbody2D rb;
    private Vector3 velocity = Vector3.zero;

    void Update()
    {
    float horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;

    MovePlayer(horizontalMouvement)
    }

    void MovePlayer(float _horizentalMouvement)
    {
    Vector3 targetVelocity = new Vector2 (_horizentalMouvement, rb.velocity.y);
    rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity,05f)
    }
    }

     
  7. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Step 1: Read the very first post in this forum: Using Code Tags Properly.
    Step 2: Post your question observing Step 1
    Step 3: Everyone loves you
    Step 4: You receive no response
    Step 5: You realize that you still did not post a question.
    Step 6: Enlightment ensues
    ????
    Step 8: Everyone profits
     
  8. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    what ?
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    So
    1) Use [code ] not [icode ]. The formatting is better and you get line numbers.
    2) Don't just say "script errors". Copy and paste the actual errors. The errors have a lot of information that will allow use to go straight to the problem.
    3) Begging ("pls help me") only makes us annoyed
    4) You're missing several semicolons, which is probably your problem.
    5) Don't let the fact that I gave you #4 make you think it's okay to ignore 1-3 in future posts
     
  10. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    are there any errors in my script ?
    Code (CSharp):
    1.  using UnityEngine;
    2.  
    3. public class PlayerMouvement : MonoBehaviour
    4. {
    5.     public float MoveSpeed;
    6.  
    7.     public Rigidbody2D rb;
    8.     private Vector3 velocity = Vector3.zero;
    9.    
    10.     void Update()
    11.     {
    12.         float  horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed  * Time.deltaTime;
    13.  
    14.         MovePlayer(horizontalMouvement)
    15.       }
    16.  
    17.     void MovePlayer(float _horizentalMouvement)
    18.     {
    19.         Vector3 targetVelocity = new Vector2 (_horizentalMouvement, rb.velocity.y);
    20.         rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity,05f)
    21.     }
    22. }
    23.  
     
  11. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
  12. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    My error Assets\script\PlayerMouvement.cs(20,88): error CS1002: ; expected
     
  13. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    Seems like a pretty straightforward and helpful error to me - tells you exactly what you need to add and where.
     
  14. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    You have a missing semicolon on line 20.

    (Quite a drawn-out thread for this to be the issue).
     
    Teamcipo likes this.
  15. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    new error : Assets\script\PlayerMouvement.cs(14,40): error CS1002: ; expecte
     
  16. Teamcipo

    Teamcipo

    Joined:
    May 12, 2020
    Posts:
    10
    I understood thank you very much
     
  17. HypnotistDK

    HypnotistDK

    Joined:
    Feb 14, 2016
    Posts:
    15
    Now your missing a semicolon on line 14 ;)