- Home /
The question is answered, right answer was accepted
Have create a script named "Screen", now my game won't work, please help
Hello, I made a huge mistake. I named one of my script "Screen" but it's a class used by unity. When I saw my error I immediately delete the script, it was too late... Do you know how I could fix that ? It's my very first game, I was proud of it and I can't work on it anymore, I know that there is a solution but I can't find it anywhere. I always have an error, because I use screeen.height and screen.width and now I receive the message "Screen doesn't contain a definition for height". I really need your help, I just ruined several weeks of work.
Answer by BSR16 · Sep 24, 2020 at 02:55 PM
Using the class names that Unity uses is not a mistake. But it is needed to be careful when using it because the compiler can confuse where to use which. In your case, the compiler thinks that the Screen class is the class you wrote. You can say that Unity should use its own Screen class like that:
int width = Screen.width;
// change the line with below line:
int width = UnityEngine.Screen.width;
If you will only use Unity's Screen class in that script, you can add the following to the beginning of your script instead of the above method:
using Screen = UnityEngine.Screen;
Follow this Question
Related Questions
JS Class "Does not denote valid type" 0 Answers
Unknown shape on screen (galaxy s4) 0 Answers
Turned screen 1 Answer
Weird canvas screen space overlay bug making whole screen black 0 Answers