Click here to Skip to main content
15,358,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It keeps giving me the semicolon error but I have every statement ended with a semicolon.

C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    
    void OnCollisionEnter2D (Collision2D collision)
    {
        if (normalE.tag == "normalEnemyTag")
        {
            currentScore + normalEnemy;

        }

        if (eliteE.tag == "eliteEnemyTag")
        {
            currentScore + eliteEnemy;
            
        }

        Destroy(collision.collider.gameObject);
        Destroy(gameObject);
        
    }
    
}


Here's the alternative code which uses the else statement that has the same error
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    
    void OnCollisionEnter2D (Collision2D collision)
    {
        if (normalE.tag == "normalEnemyTag")
        {
            currentScore + normalEnemy;

        }

        else
        {
            currentScore + eliteEnemy;
            
        }

        Destroy(collision.collider.gameObject);
        Destroy(gameObject);
        
    }
    
}


What I have tried:

I tried rereading every line and letter by letter. I don't really know what's wrong
Posted
Updated 11-May-22 4:20am
v2
Comments
Richard Deeming 11-May-22 12:11pm
   
The error message will include a filename and line number, which should tell you where to start looking.

Are you sure it's a CS1002 error, and not a CS0201 error on the two lines starting currentScore + ?

1 solution

You missed the semicolon at the end of the class declaration.
I assumed it was C++, my bad.


Please note:
Quote:
currentScore + normalEnemy;
has no effect. Possibly you meant
C++
currentScore += normalEnemy;
   
v2
Comments
Richard Deeming 11-May-22 12:09pm
   
C# doesn't need a semicolon at the end of a class. :)
CPallini 11-May-22 13:20pm
   
IS it C#? OOOOOOPS!
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900