hi i have a problem pls help me CS0116

i have CS0116 error in line 50,14:A name space

here my script: line 50
private void OneCollisionEnter2D(Collision2D collision)

file is here

thx :slight_smile:

7430693–909971–baban.cs (1.07 KB)

This is a basic C# problem not a 2D problem so looks like you’re new to the C# language and might be guessing at how it all works.

You’ve added the “OneCollisionEnter2D” method outside of the class. Looks like you just stuck it at the end of the file which is incorrect. Put it alongside the other methods in your class.

Also, note that it’s not "One, it’s “On” i.e. OnCollisionEnter2D.

Hope that helps.

Thx <3 but i cant do this can you help me in line 50

Cannot do what part?

If you don’t follow what I said then I would suggest looking at some C# tutorials because the forums here are not places for guessing how the C# language works.

Here’s what it looks like when you move it into the class:

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

public class baban : MonoBehaviour
{
    public Rigidbody2D rb;

    // Start is called before the first frame update
    void Start()
    {
     
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(new Vector2(0, 600));
        }

        if(rb.velocity.x > 6)
        {
            rb.velocity = new Vector2(6, rb.velocity.y);
        }

        if(rb.velocity.x < -6)
        {
            rb.velocity = new Vector2(-6, rb.velocity.y);
        }

    }

    private void FixedUpdate()
    {
        if(Input.GetKey(KeyCode.A))
        {
            rb.AddForce(new Vector2(-30, 0));
        }
     

        if(Input.GetKey(KeyCode.D))
        {
            rb.AddForce(new Vector2(30, 0));
        }
    }

    private void OneCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.tag=="Enemy")
        {
            Time.timescale = 0;
        }

    }
}

As I said though, “OneCollisionEnter2D” isn’t correct and won’t be called by Unity because it’s spelled incorrectly.

1 Like