error CS0106: The modifier 'private' is not valid for this item

Hello again, can you guys help me with this problem? I don’t know how to resolve it, i think i’m dumb.
Here’s the code:

using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour
{
    [Header("BulletConfig")]
    public int range;
    public int damage;
    public float mass;
    public float speed;
    [Header("Imports")]
    public PlayerController Player;
    public ParticleSystem impact;

    //Privates
    private Rigidbody rb;
    private Vector3 origin;

    void Start()
    {
        rb = GetComponents<Rigidbody>();
        origin = transform.position;
    }

    void Update()
    {
        //Massa
        rb.mass = mass;

        //Frente
        Vector3 horizontal = transform.right * 0;
        Vector3 vertical = transform.forward * 1;
        Vector3 velocity = (horizontal + vertical).normalized * speed;
        rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);

        //Range
        if (Vector3.Distance(origin, transform.position) > range)
        {
            Destroy(GameObject);
        }

        private void OnCollisionEnter(Collision collision)
        {
            Destroy(gameObject);
            if (collision.gameObject.tag == "Terrain")
            {
                GameObject eff = Instantiate(impact, collision.transform.position, Quaternion.Identity).gameObject;
                eff.transform.position += new Vector3(0, 0.1f, 0);
                eff.transform.eulerAngles = new Vector3(-90, 0, 0);
            }
        }
    }
}

I’m really dumb :face_with_spiral_eyes:

1 Like

The OnCollisionEnter method is inside the Update method. You need to rearrange your methods. Mainly the }-s.

1 Like

I need to put on Start method? Or on the “//Privates”?

Just move the } in the 52th line to the 41st line.

BTW, seeing your opened threads on the forums, you really need to learn how to format a basic C# script. Maybe this will help:

https://www.youtube.com/watch?v=sQurwqK0JNE

Yes, i need help

Assets\skript\Enemy.cs(72,9): error CS0106: The modifier ‘private’ is not valid for this item

How to understand compiler and other errors and even fix them yourself:

https://forum.unity.com/threads/assets-mouselook-cs-29-62-error-cs1003-syntax-error-expected.1039702/#post-6730855

Remember: NOBODY memorizes error codes. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

Always start with the FIRST error in the list, as sometimes that error causes or compounds some or all of the subsequent errors.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

I just ran into the same problem i cannot believe how stupid i was thx for da fix

Thank you this helped with my issues as well