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) }
Please use inline code insertion. Will be easier to read. Code (CSharp): 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) } 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.
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
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