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

Need Help with Code

Discussion in '2D' started by DukkKK, Feb 5, 2021.

  1. DukkKK

    DukkKK

    Joined:
    Feb 5, 2021
    Posts:
    15
    It keeps saing Assets\Playermovement.cs(35,63): error CS1003: Syntax error, ',' expected
    this is my code sorry that it's a lot

    public class Playermovement : MonoBehaviour {
    public float movementSpeed;
    public Rigidbody2D rb;

    public float JumpForce = 90f;
    public Transform feet;
    public LayerMask groundLayers;

    float mx;

    private void Update() {
    mx = Input.GetAxisRaw("Horizontal");

    if (Input.GetButtonDown("Jump") && IsGrounded()) {
    Jump();
    }
    }
    private void FixedUpdate() {
    Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);

    rb.velocity = movement;
    }

    void Jump() {
    Vector2 movement = new Vector2(rb.velocity.x, JumpForce);

    rb.velocity = movement;
    }

    public bool IsGrounded() {
    Collider2D groundCheck = Physics2D.OverlapCircle(Our Boi.posision, 0.5f, groundLayers);

    if (groundCheck != null) {
    return true;
    }

    return false;
    }
    }
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,333
    Can you edit your post and repaste your code with code tags? It is difficult to read as is.

    upload_2021-2-5_14-56-24.png
     
    DukkKK likes this.
  3. DukkKK

    DukkKK

    Joined:
    Feb 5, 2021
    Posts:
    15
    Code (CSharp):
    1. public class Playermovement : MonoBehaviour {
    2. public float movementSpeed;
    3. public Rigidbody2D rb;
    4.  
    5. public float JumpForce = 90f;
    6. public Transform feet;
    7. public LayerMask groundLayers;
    8.  
    9. float mx;
    10.  
    11. private void Update() {
    12. mx = Input.GetAxisRaw("Horizontal");
    13.  
    14. if (Input.GetButtonDown("Jump") && IsGrounded()) {
    15. Jump();
    16. }
    17. }
    18. private void FixedUpdate() {
    19. Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
    20.  
    21. rb.velocity = movement;
    22. }
    23.  
    24. void Jump() {
    25. Vector2 movement = new Vector2(rb.velocity.x, JumpForce);
    26.  
    27. rb.velocity = movement;
    28. }
    29.  
    30. public bool IsGrounded() {
    31. Collider2D groundCheck = Physics2D.OverlapCircle(Our Boi.posision, 0.5f, groundLayers);
    32.  
    33. if (groundCheck != null) {
    34. return true;
    35. }
    36.  
    37. return false;
    38. }
    39. }
    yes there you go
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,333
    So its hard to tell exactly because sometimes that error can mean too many or too little parentheses AND you didnt include the entire script including namespaces so where the error says the line (35,63) i cant see exactly what line. But, my guess is this:

    upload_2021-2-5_17-2-23.png
    the Our Boi is probably mistyped and that Space is confusing Unity. If it is a typo, just fix that and hopefully it should work. If that is actually your variable, try renaming it without the space or throw in an _ to fix it. If you change it and there is still the same error, copy and paste the entire code (with namespaces) so the error line # lines up with the code you post. Thank you for editting you post with code tags, it really does help.
     
  5. DukkKK

    DukkKK

    Joined:
    Feb 5, 2021
    Posts:
    15
    Thank you for the help and I did copy and paste the entire thing I don't have any higher than 39
     
  6. DukkKK

    DukkKK

    Joined:
    Feb 5, 2021
    Posts:
    15
    There is a new error
    Assets\Playermovement.cs(35,66): error CS1061: 'Transform' does not contain a definition for 'posision' and no accessible extension method 'posision' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Playermovement : MonoBehaviour {
    6.     public float movementSpeed;
    7.     public Rigidbody2D rb;
    8.  
    9.     public float JumpForce = 90f;
    10.     public Transform Player;
    11.     public LayerMask groundLayers;
    12.  
    13.     float mx;
    14.  
    15.     private void Update() {
    16.       mx = Input.GetAxisRaw("Horizontal");
    17.  
    18.        if (Input.GetButtonDown("Jump") && IsGrounded()) {
    19.            Jump();
    20.        }
    21.        }
    22.       private void FixedUpdate() {
    23.          Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
    24.  
    25.          rb.velocity = movement;
    26.       }
    27.      
    28.       void Jump() {
    29.          Vector2 movement = new Vector2(rb.velocity.x, JumpForce);
    30.  
    31.          rb.velocity = movement;
    32.       }
    33.  
    34.       public bool IsGrounded() {
    35.          Collider2D groundCheck = Physics2D.OverlapCircle(Player.posision, 0.5f, groundLayers);
    36.  
    37.          if (groundCheck != null) {
    38.              return true;
    39.          }
    40.  
    41.          return false;
    42. }
    43. }
    44.  
    This is the full code
     
  7. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    480
    You need to spell things correctly. It should be
    position
     
  8. DukkKK

    DukkKK

    Joined:
    Feb 5, 2021
    Posts:
    15

    oh my goodness I'm so dumb