{Help] Words are not being highlighted blue or red for me

As you can see in the first Screenshot the instructor’s code has the word “States” colored blue and “corridor_0” colored red. The screenshot of my code (the second image) has neither.

My code works and the game runs just like the instructor’s game (which means my “corridor_0” wouldn’t be red. But the word “States” should be blue) but at no time did any of these words turn red or blue.

Is there a setting I’m missing somewhere?

Can you post your code rather than the screenshots, the first few lines of your script are not visible and often thos type of issue points to a missing bracket, curly brace or semi-colon before the line in issue.

Link to code at github
Sorry about that. This is all new to me and using a code hosting service is new to me too. let me know if I didn’t do this right.

I think the problem lies in the first few lines,

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

I think it is because you do not have that in your code, but I could be wrong.

I’m pretty sure that’s where the problem is, you might have them in your code but there is something wrong with these lines of code, maybe a missing semicolon or something like that.

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

Thanks for the suggestion wcoltd. You’re right, I didn’t have those things declared (to be honest I don’t know what those are or if “declaring” them is the correct terminology).

This is what I had:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

I double checked the course code to be sure I didn’t miss the instructor adding it and this is the same thing that is on the course code. But just to be sure I added what you sugested (commenting out what I had originally) and tested my game to be sure it still ran.

It does still run correctly but the words are still not changing color. :confused:

Thanks for the suggestion though.

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

The above are directives that instruct your class to use any of those namespaces, they allow you to access other classes that are within. The reason I asked for the full script was because it was difficult to see if you had a missing semi-colon for example after one of them, which may cause you this problem.

Most of those you don’t actually need anyway, unless you are doing something that specifically accesses something from within one. For example, your line;

public Text text;

would error if you didn’t have;

using UnityEngine.UI

as the compiler wouldn’t know what the type Text was in this context.

The fact that your game runs indicates that there isn’t a problem with your code. I’ve taken a copy of the code from the link you provided and pasted it into Visual Studio, this is how it looks for me;

as you can see, States is in lightblue, which indicates all is good. What this suggests is perhaps your installation of MonoDevelop has a problem with the syntax highlighting.

Within MonoDevelop try going to Tools > Preferences and then click on the Text Editor tab, there should be an item for syntax highlighting, if there’s nothing obvious, can you pop a screenshot of that up, as I’ve not used it for some time.

Incidentally, Visual Studio is a much more advanced development environment, so if you have continued problems I would recommend switching to Visual Studio, there is now a Mac version and you can get it for free. MonoDevelop is actually built using an open source version of what Visual Studio was, once upon a time, as such it’s a little further being in the development time frame.

Also, note how in my screenshot the using System.Collections; is greyed out, that’s because Visual Studio lets you know if you are referencing things that you don’t actually need, as such you could remove that line altogether and you’d still be fine - quite a handy feature.


Thank you for all this. Both the explanation and the suggestions. Maybe I’ll switch to Visual Studio.
Here is the screenshot of my preferences in MonoDevelop. Nothing seems to be amis. As you pointed out it doesn’t ultimately matter because my game works. I just would like the extra assurance that I’m using correct syntax or if I need to declare something and the like. The instructor uses the highlighting as a tool a lot to double check his code.

Thank you for the explanation on what directives are and why I need them. That is super helpful. How do I know beforehand what directives I need? The only reason I put these in was because I was following the instructor line by line. I don’t actually know where he got these from or how to find them on my own when making my own games.

I wpuld lile to be able to help.you further with the highlighting issue but I dont have a Mac so it isn’t really possible for me to replicate the issue at my end.

Another thought of course is whether it is just an issue with a specific version of MonoDevelop/Unity, the only way to test that theory though would be to install a newer veraion and see if the issue goes away.

If.you do go down that road, be aware tjat on a Mac Unity doesn’t give you a choice for the install path, so if you want to keep an older version as well you need to rename to directory first. Typically it is advisable to include the version number in the directory name. Your new install will then install to the default path.

Regarding the usinf directives. You just need to know which class(es) belong to which namespace, that can be found in one of two places.

If it is for Unity specific classes then the Unity documentation is the place to go. As am example, the SceneManager documentation, note it displays the namespace for the class.

If it is just standard C# then the Microsoft website wpuld be the place to visit.

In both cases the shortest route will invariably be via Professor Google :slight_smile:

Excellent. I totally understand about not being able to delve deeper into the highlighting issue. I’ll try a different version of Unity first and maybe later try it on a PC. I’ll update my findings once I do them. Thanks for your help in this matter.

And thanks for the explanation of directives and where to find them. I’ll look into that as well.

1 Like

You are more than welcome :slight_smile:

Privacy & Terms