Code error with character controller

I’ve entered the same code as Ivan in the video but I’m getting an error from unity.

assets/scritps/playercontroller.cs(15,43): error cs1525: Invalid expression term ‘)’

Here’s the code I wrote and that was in the video.

rb = GetComponent<RigidBody 2D>(); (FYI, RigidBody2D as written in the video gave me an error because unity places a space between RigidBody and 2D in the “get component” section.

It’s giving an error for the close parenthesis. Any ideas what needs to be fixed?

I think I figured this out but now I’m having another error. Basically the PlayerController isn’t showing up in the add component section when I search for it. So I can’t control my jelly at all. The error I’m getting is playercontroller.update() must declare a body because it is not marked abstract, extern or partial. I’ve watched over the videos a few times and I believe the code is correct but Unity is not allowing me to add the player controller component. Thanks for any help

1 Like

Could you please share your code in the following way? It will be easier for us to understand the issue and help you solve it :nerd_face:

Carlos Z

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    
    public float speed;
    public float jumpforce; 

    public float jumpsAllowed;
    private float timesJumped;

    private Rigidbody2D rb; 
    private float MoveInput; 
    private float jumpInput;
    private float previousJumpInput; 

    private bool isJumping;
    
    // Start is called before the first frame update
    void Start()
    {
        rb  =  GetComponent<RigidBody2D>();
        isJumping = false;
        timesJumped = 0;
        previousJumpInput = 0; 
    }
    
    void FixedUpdate()
{

       MoveInput = Input.GetAxis("horizontal");
       rb.velocity = new vector2(moveinput*speed, rb.velocity.y);
       JumpInput = Input.GetAxis("vertical");
       if(JumpInput > 0 && timesJumped < jumpsAllowed && previousJumpInput == 0);
    { 
       rb.velocity = new vector2(rb.velocity.x, jumpforce); 
       timesJumped++; 
    }

    previousJumpInput = jumpInput;
}    
 
    void OnCollisionEnter2D(Collision2D other)
    {
        if(other.gameObject.CompareTag("Ground"))
        {
            timesJumped = 0;
        } 
    }
    // Update is called once per frame
    void Update();

}

In your PlayerController the update function should contain at least the body brackets {}

Carlos Z