UnityEngine.Screen does not contain a definition for 'fullscreen'
It's been a whole two weeks now with my fullscreen bug, and it seems that no one cares anymore, and I can't seem to figure it out myself, now I have updated my code to better fit the toggle button, and I get a total of 13 errors in this order:
A 'using' directive can only be applied to namespaces but 'UnityEngine.Screen' denotes a type. Consider using a 'using static' instead "Line 4"
Feature 'using static' cannot be used because it is not part of the C# 4.0 language specification "Line 4"
Unexpected symbol 'public', expecting ',' or ';' "Line 5"
The contextual keyword 'var' may only appear within a local variable declaration "Line 15"
'UnityEngine.Screen' does not contain a definition for 'fullscreen' "Line 15"
'UnityEngine.Screen' does not contain a definition for 'fullscreen' "Line 16"
'UnityEngine.Screen' does not contain a definition for 'fullscreen' "Line 17"
The left hand side of an assignment must be a variable, a property or an indexer "Line 26"
The left hand side of an assignment must be a variable, a property or an indexer "Line 27"
The left hand side of an assignment must be a variable, a property or an indexer "Line 28"
'UnityEngine.Screen' does not contain a definition for 'fullscreen' "Line 31"
'UnityEngine.Screen' does not contain a definition for 'fullscreen' "Line 32"
'UnityEngine.Screen' does not contain a definition for 'fullscreen' "Line 33"
Errors are killing me slowly, but here is the code so you can possibly help:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FullscreenToggle : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (!Screen.fullscreen)
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
//Replace this with whatever logic you want to use to validate the objects you want to click on
if (hit.collider.gameObject.tag == "Toggle")
{
!Screen.fullScreen = Screen.fullScreen;
}
}
}
}
if (Screen.fullscreen)
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
//Replace this with whatever logic you want to use to validate the objects you want to click on
if (hit.collider.gameObject.tag == "Toggle")
{
Screen.fullScreen = !Screen.fullScreen;
}
}
}
}
}
}
Not to be rude or anything, but someone please answer this question this time, this is my fourth time I've asked a question related to my games fullscreen bug and not a single person has replied. And at this point I'm done. >:-(
Answer by Jawchewa · Jun 08, 2017 at 08:06 PM
I'm not sure about all the errors at the beginning with the using statements. I think that might be an issue with your Unity setup, but the code itself looks syntactically correct. Although, I think I can help you with your fullscreen issue.
On lines 16 and 32, the issue is that you are trying to access Screen.fullscreen. The problem is that the "s" in fullscreen has to be capitalized. Change it to Screen.fullScreen instead.
Your issue on line 27, is that you have the exclamation symbol in the wrong place. It should look more like this:
Screen.fullScreen = !Screen.fullScreen;
Hope this at least helps with part of your problem.
@Jawchewa thank you for fixing my fullscreen bug, it no longer says fix all errors before running. BUT! When i built the game, it still did not go fullscreen, no matter how many times I clicked, please help, if you can
I think the issue here is that it is hitting your first block of code, which sets fullscreen to true, and by the time it hits the second block of code that checks if it is already true, it is immediately setting it back to false. The easiest solution would be to simply replace the if (Screen.fullScreen)
with an else statement, so that it doesn't immediately fire afterwards.
However, the way your code is set up now seems kind of redundant to me. The two parts inside of the main ifs seem like they are doing the exact same thing. If I were you, I would get rid of the second part entirely, by changing your update to something like this:
void Update()
{
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
//Replace this with whatever logic you want to use to validate the objects you want to click on
if (hit.collider.gameObject.tag == "Toggle")
{
Screen.fullScreen = !Screen.fullScreen;
}
}
}
}
@Jawchewa thank you for the fix, but it's still not working! I did everything you told me to except for the else statement due to getting rid of the second statement. Since that the code is all the same, I'll send you an image of the toggle, If there is anything wrong here, it would be great to know!
Answer by CaveGames · Jun 09, 2017 at 12:33 AM
@Jawchewa thank you for helping me, it now turns on, but was is the command for turning it off? I chose to no longer have toggle and replace it with on/off, and the on works, but the off doesn't. If you have an answer, and it works, I will tell you.
Well, with the toggle, it should just set it to whatever state it isn't currently in, so you would just have to click it twice to turn it on and off. I think it should be doing that already. If you want to split it into two parts, you will need to split it into two parts, so
Screen.fullScreen = true;
will set it to fullscreen, and
Screen.fullScreen = false;
should change it back to windowed.
@Jawchewa it still doesn't work! Granted, the on button works, and that is not a problem anymore, but the off doesn't! I have it all set up, in the way you wanted, but in separate scripts titled FullscreenOn and FullscreenOff, and they both have no errors, except that when I built the latest alpha, it would turn on but wouldn't turn back off!
Your answer
Follow this Question
Related Questions
Set Fullscreen With Raycast 0 Answers
User Layer that Ignores Raycast? 2 Answers
How do I use Input.GetButton, instead of OnMouse() 1 Answer
raycast mouse detects any object 1 Answer
Click or Drag but not both 1 Answer