Weird Script

Hi!
I wrote the Script that rick showed in the video.
I checked for Errors and it said that in line 144, 206 there were mistakes. I was a bit confused, because I only wrote 31 lines of code. I looked a bit around, and I saw the Script ParticleScene.cs with 53 errors and 234 lines of Code. I don’t know what to do, I obviously didn’t write the script. Why is it here

and why does it have so many errors ??.
Is the script importand?? I wanted to check before I delete 234 lines of script that I might need later… :laughing:

1 Like

Hi,

MonoBehaviour does not have the same colour as your classname. This indicates that there is very likely a problem with Visual Studio. Please watch lecture “Fixing Visual Studio Problems” (currently #4). I am aware that you are using VSC but there are a few more tips in the video which don’t have anything to do with a specific IDE.

Which version of Unity do you use? Have you already tried to restart Unity and Visual Studio Code? Is Visual Studio selected as your External Script Editor in Unity (Edit > Preferences > External Tools)?

Apart from things directly in the C# language - keywords, primitives, and the like - everything else you make use of is either written by you or has to be referenced to bring it into scope.

So “float” for example it’s fine with, this is a language definition.

“Text” or “Monobehavior” for example do not belong to the C# language. To bring those in you have to have the correct references, which are done with “using” statements at the top of the file.

E.g. (from one of my monobehaviors of old that has Text and other items in it):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Text;

public class ScoreDisplay : MonoBehaviour
{

        public Text[] scores;
        public Text[] frameTexts;

...

Note that without lines like using UnityEngine; at the top, your code editor (and C#) don’t know what a MonoBehavior is, so it will underline it in red. Same goes for having using UnityEngine.UI; so that it knows what a Text is, and so on.

Get started with that, and maybe using System; as well, and see how many of the reds that gets rid of for you (hopefully most!).

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms