need help with the Invalid token ';' in class, struct, or interface member declaration error

I am very new and would like some help with this error. Line 15 is where the error is. Ask me for more info if you need it.

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

public class bullet2 : MonoBehaviour
{   private Vector3 velocity;



    public float speed = 20;
    
    
    public float damage = 15;

     public boolet;

    // Start is called before the first frame update
    void Start()
    {
       velocity = transform.forward * speed;
    }

    // Update is called once per frame
    void Update()
    {
           transform.position += velocity * Time.deltaTime;
           Destroy (boolet, 5f);
   
    }
    void OnCollisionEnter (Collision collision)
    {
        GameObject objecthit = collision.collider.gameObject;
       
        if (objecthit.CompareTag ("Player"))
        {
            objecthit.SendMessage ("Damage", damage, SendMessageOptions.DontRequireReceiver);
           
           
           
        }
       
    }
   
   
}

Good job posting the code in a proper code block, and pointing out the line number where the error occurs. A lot of newbies mess that up.

The problem here is that every variable declaration needs a type. Line 15 says you want a variable called “boolet” which is public (accessible from outside the class). But what is it? A string? A float? An int? A Vector3? It could be anything; the compiler has no idea what you want because you didn’t say. Thus the error.

Since you’re passing it into Destroy, I guess you probably meant it to be a GameObject reference. So it should be

public GameObject boolet;
1 Like

Thank you for the info, it really helps!

2 Likes