How to fix these errors?

Hi everyone, I’m starting my adventure with C # and unity from scratch, and I need some help.What’s wrong with this code? Two errors are displayed:

1)Assets\Platform.cs(13,76): error CS1525: Invalid expression term ‘if’
2)Assets\Platform.cs(13,76): error CS1002: ; expected

  using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Platform : MonoBehaviour
    {
        public float jumpForce = 10f;
    
        private void OnCollisionEnter2D(Collision2D collision)
        {
            if (collision.relativeVelocity.y <= 0f)
            {
                Rigidbody2D rb = collision.gameObject.GetComponent<Rigidbody2D>
                if (rb != null)
                {
                    Vector2 velocity = rb.velocity;
                    velocity.y = jumpForce;
                    rb.velocity = velocity;
                }
            }
        }
    }

Hi!

This is a simple syntax problem. If you look at the error ( Assets\Platform.cs(13,76): error CS1002: ; expected) You can see the line where the error is (line 13, character 76) and that the compiler expects a semicolon.

Line 13 is this one:

Rigidbody2D rb = collision.gameObject.GetComponent<Rigidbody2D>

Adding a semicolon at the end will make that error disappear.

You will also need to add the brackets(), since it is a function, otherwise another error will appear.

So basically change your line to this:

Rigidbody2D rb = collision.gameObject.GetComponent<Rigidbody2D>();

Hope this helps!