The local function 'OnCollisionEnter2D' is declared but never used

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;

public class CharacterCtrl : MonoBehaviour
{
    public int Speed;
    public int JumpForce;
    public GameObject Character;
    public GameObject Coin;
    public Rigidbody2D rb2D;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
        {
            rb2D.velocity = Vector2.left * Speed;
        }

        if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) | Input.GetKeyDown(KeyCode.RightArrow))
        {
            rb2D.velocity = Vector2.right * Speed;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb2D.velocity = Vector2.up * JumpForce;
        }

        void OnCollisionEnter2D(Collision collision)
        {
            Debug.Log("d")
        }

    }
}

Here’s my full code for context

I tried putting a semicolon, didn’t change a thing (cant believe i forgot)

You have put the OnCollisionEnter2D method inside your Update method. You should move it out of there.

3 Likes

Just tried that. Thanks! but now it says it has an incorrect signature???
Oh, btw my editor version is 2022.3.8f1 if that helps

Nvm got it! (google for da win)