Search Unity

error CS1514

Discussion in '2D' started by Midnaplays123, Nov 30, 2020.

  1. Midnaplays123

    Midnaplays123

    Joined:
    Nov 30, 2020
    Posts:
    11
    i can´t find the error :|


    Rigidbody2D rbi
    float horizontal;
    [SerializeField] private float speed;

    {
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    rb = GetComponent<Rigidbody>();
    }
    }

    static void FixedUpdate(float speed) {
    horizontal = Input.GetAxis("Horizontal");
    rb.velocity = new Vector2(horizontal * speed, rb.velocity)
    }
     
  2. MrPaparoz

    MrPaparoz

    Joined:
    Apr 14, 2018
    Posts:
    157
    Please use inline code insertion. Will be easier to read.

    Code (CSharp):
    1.  
    2. Rigidbody2D rbi
    3. float horizontal;
    4. [SerializeField] private float speed;
    5.  
    6. {
    7. // Start is called before the first frame update
    8. void Start()
    9. {
    10.  
    11. }
    12.  
    13. // Update is called once per frame
    14. void Update()
    15. {
    16. rb = GetComponent<Rigidbody>();
    17. }
    18. }
    19.  
    20. static void FixedUpdate(float speed) {
    21. horizontal = Input.GetAxis("Horizontal");
    22. rb.velocity = new Vector2(horizontal * speed, rb.velocity)
    23. }
    Problem is you made Unity's built-in event function "FixedUpdate" into static. Remove static keyword and also remove parameter "float speed".

    Edit: also this question belongs to Scripting forum.
     
    MelvMay and eses like this.
  3. mojdrug7

    mojdrug7

    Joined:
    Dec 24, 2020
    Posts:
    1
    Rigidbody2D rbi - problem in this part, u need ;
     
  4. Zapp36

    Zapp36

    Joined:
    May 18, 2021
    Posts:
    13
    pls someone help me i dont know how to fix it heres my script:
    using UnityEngine;
    public class PlayerMovement : MonoBehaviour
    public CharacterController controller;
    public float speed = 12f;
    // Update is called once per frame
    void Update()
    {
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");
    Vector3 move = transform.right * x + transform.forward * z;
    controller.Move(move * speed * Time.deltaTime);
    }
    }

    error : Assets\PlayerMovement.cs(3,48): error CS1514: { expected
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Do not cross post all over the place. As in the other thread which you hijacked there too, you should use code-tags when posting code.

    This post should be in the scripting forums because it's a syntax error you've created because it's clear you should really look at a basic C# programming tutorial.

    The code above isn't how you create a class or MonoBehaviour in C#. A class defines curly braces { } to encapsulate what's inside it. Almost any scripting tutorial in Unity would show you this so I'd recommend spinning a few up.

    https://learn.unity.com/project/beginner-gameplay-scripting