Why does Unity say "error CS0106: The modifier 'private' is not valid for this item".

This is the code. I am trying to make my chracter not being able to jump forever.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GroundCheck : MonoBehaviour
{
GameObject Jay;
// Start is called before the first frame update
void Start()
{
Jay = gameObject.transform.parent.gameObject;
}

// Update is called once per frame
void Update()
{

private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag == “Ground”)
{
Jay.GetComponent().isGrounded = true;
}
}

private void OnCollisionExit2D(Collision2D collision)
{
if (collision.collider.tag == “Ground”)
{
Jay.GetComponent().isGrounded = false;
}
}
}
}

Hey and welcome.

Please use code tags for the next post you do. Also, posting the full error message, including the line, helps.

The problem is that you are declaring your OnCollisionEnter2D method inside the Update method (marked by its curley brackets). That’s why it’s telling you that ‘private’ is not allowed there. Pull that method out of there.

Thx for the help. I saw you said to use code tags in my next post what is that?

Also how do i close the post as solved

Code tags .

i have the same problem check out my posts

You only have this one post. But if you have the exact same problem then the the solution would also be exactly the same, as described above.

3 Likes