Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Getting referencing error when trying to position a GUI screen.

$
0
0
Hello, I've started making a game and want to put an introduction GUI screen at the beginning of the first level. I need to position the screen directly in the center of whatever screen the user is currently using. With C#, I've created this script: using UnityEngine; using System.Collections; public class OpeningIntroduction : MonoBehaviour { public bool isGUIOpen = true; // Use this for initialization float windowWidth = Screen.width * 0.7f; float windowHeight = Screen.height * 0.7f; float displacementWidth = (Screen.width) - (windowHeight/2.0f); float displacementHeight = (Screen.height) - (windowHeight/2.0f); void OnGUI () { if(isGUIOpen = true){ GUI.Box (new Rect(displacementWidth,displacementHeight,windowWidth,windowHeight),"Test"); } } void Start () { } // Update is called once per frame void Update () { } } However, when I run it, I get this error: \ A field initializer cannot reference the nonstatic field, method, or property `OpeningIntroduction.windowHeight' \ This error seems to be pointing to the 9 and 10 lines, but I don't see any problems with them. Any help would be very much appreciated. Thanks in advance.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>