Error code in Unity Engine but not Visual Studio

Hi. I am making a minigame using if( ) and switch statements. When I try to run the game, I get these errors, but there are no errors in Visual Studio. Any help would be appreciated.

This is my C# script:

using UnityEngine;
using TMPro;
using System.Collections;
public class CarMovement : MonoBehaviour
{
   // declare public Text variables
   public TextMeshProUGUI speedText;
   public TextMeshProUGUI damageText;
   public TextMeshProUGUI timeText;
   public TextMeshProUGUI gameOverText;

   // declare class variables to track 
   // speed, damage, and elapsed time
   float speed = 1.0f;
   int damage = 0;
   float elapsedTime = 0;

   // this flag will become true when the game is over
   bool gameOver = false;

   // Use this for initialization
   void Start()
   {
       // initialize all of the Text display messages
       speedText.text = "Speed: " + speed;
       damageText.text = "Damage: 0";
       timeText.text = "Time: 0";
       gameOverText.text = "";
   }

   // Update is called once per frame
   void Update()
   {
       // only process movement and new time if the
       // game is not yet over
       if (!gameOver)
       {
           // Move the car in current direction at
           // the current speed.  Translation in the "X"
           // direction will move an object forward at
           // it's current rotation angle. Adjust the 
           // 0.02F scale factor to move faster or slower.
           transform.Translate(speed * Time.deltaTime, 0, 0);

           // Get steering left/right input.  Adjust
           // the 100.0F scale factor to turn faster
           // or slower
           float rotation = Input.GetAxis("Horizontal") * 100.0F;

           // rotate car left or right according to current input
           // (rotation will be 0 if no input)
           transform.Rotate(0, 0, -rotation);

           // add time since the last frame to our measure
           // of overall elapsed time
           elapsedTime += Time.deltaTime;

           // update the timeText message, converting float to int
           timeText.text = "Time: " + (int)elapsedTime;
       }
   }

   void OnTriggerEnter2D(Collider2D otherObject)
   {
       // get the name of the object we triggered
       string otherName = otherObject.gameObject.name;
       Debug.Log("Trigger on " + otherName);

       // take different actions depending on the other 
       // object's name
       switch (otherName)
       {
           case "finishLine":
               gameOverText.text = "Finished!";
               break;
           case "oilHazard1":
           case "oilHazard2"
           case "oilHazard3"
           case "oilHazard4"
            if (speed > 2.0f)
            {
               speed -= 1.0f;
                   speedText.text = "Speed: " + speed;
            }
            break;
           case "speedBoost1":
           case "speedBoost2":
           case "speedBoost3":
           case "speedBoost4":
               speed += 1.0f;
               speedText.text = "Speed: " + speed;
               break;
           default:
               // This will not be used for now
           break;
       }
   }

   void OnCollisionEnter2D(Collision2D otherObject)
   {
       Debug.Log("Collision on " + otherObject.gameObject.name);

       // on any collision with an obstacle object,
       // increase damage by 1 and update the damageText display
       damage++;
       damageText.text = "Damage: " + damage;

       if(damage >= 10)
       {
           gameOver = true;
           gameOverText.text = "Wrecked!"

       }
   }
}

You’re missing the colon : on three of the case statements. I’d be very surprised if Visual Studio wasn’t showing errors there.

I added the three colons and all but one of my errors have been fixed. (Thank you for mentioning the three colons.) It gives me this error:

But when I went to Visual Studio before and after I made your corrections I was getting no errors.
Screenshot 2024-12-18 1501361
I have no idea why.

Do you get auto-complete on Unity’s types? Potentially your Visual Studio is not set up correctly.

Also just read the error. It’s saying you’re missing a semi-colon on the end of line 111.

I had tried that,

Screenshot 2024-12-19 1028091
but now it gives me five error codes.

You really need to just read the errors. It’s telling you there’s no TMPro namespace. Sounds like you haven’t installed the TMPro package.

I just noticed that none of the packages were installed.