- Home /
I need to remove the GUI from this camera script, but I don't know how.
I've been making a 2D platformer. There is a tutorial for this on the Unity website. However, in the script they use to follow the player, a GUI window will appear, allowing the player to switch characters. I want to make a game without this, because I will only use one player. The script also includes the instructions to the game, but I'm using plain text down the bottom of the screen to display that. The script is as followed:
// Script that puts a window on-screen where the player can toggle who he controls // It works by sending SetControllable messages to turn the different characters on and off. // It also changes who the CameraScrolling scripts looks at.
// An internal reference to the attached CameraScrolling script private var cameraScrolling : CameraScrolling;
// Who is the player controlling private var selected = 0;
// List of objects to control var targets : Transform[];
// What to display on the buttons in the window var targetButtonNames : String[];
// On start up, we send the SetControllable () message to turn the different players on and off. function Awake () {
// Get the reference to our CameraScrolling script attached to this camera;
cameraScrolling = GetComponent (CameraScrolling);
// Set the scrolling camera's target to be our character at the start.
cameraScrolling.SetTarget (targets[0], true);
// tell all targets (except the first one) to switch off.
for (var i=0; i < targets.Length; i++)
targets[i].gameObject.SendMessage ("SetControllable", (i == 0), SendMessageOptions.DontRequireReceiver);
}
private var windowRect = Rect (20, 20, 250, 50); // Make the onscreen GUI to let the player switch control between Lerpz and the spaceship. function OnGUI () { // Make a popup window windowRect = GUILayout.Window (0, windowRect, DoControlsWindow, "Controls");
// The window can be dragged around by the users - make sure that it doesn't go offscreen.
windowRect.x = Mathf.Clamp (windowRect.x, 0.0, Screen.width - windowRect.width);
windowRect.y = Mathf.Clamp (windowRect.y, 0.0, Screen.height - windowRect.height);
}
// Make the contents of the window function DoControlsWindow (windowID : int) { // Make the window be draggable in the top 20 pixels. GUI.DragWindow (Rect (0,0, System.Decimal.MaxValue, 20));
GUILayout.Label ("You are the brave:");
// Let the player select the character
selected = GUILayout.Toolbar (selected, targetButtonNames);
// If the user has selected a new character, we'll send new SetControllable messages to turn on the other character.
// Then we'll change who the CameraScrolling script is tracking.
if (GUI.changed && targets[selected] != cameraScrolling.GetTarget ()) {
targets[selected].gameObject.SendMessage ("SetControllable", true, SendMessageOptions.DontRequireReceiver);
cameraScrolling.GetTarget ().gameObject.SendMessage ("SetControllable", false, SendMessageOptions.DontRequireReceiver);
cameraScrolling.SetTarget (targets[selected]);
}
// Show a different instruction label depending on what was selected above.
switch (selected) {
case 0:
GUILayout.Label ("Instructions:\nUse the left and right arrow keys to move and space bar to jump.");
break;
case 1:
GUILayout.Label ("Instructions:\nUse the left and right arrow keys to rotate and the up arrow to thrust.");
break;
}
}
// Ensure there is a CameraScrolling script attached to the same GameObject, as this script // relies on it. @script RequireComponent (CameraScrolling)
Can someone please help me get rid of any GUI related things? I still want the camera to act the same way, but showing GUI and switching characters has to go. I've tried myself, but I always seem to find an error. I don't know why.
Answer by Mike 3 · Jun 21, 2010 at 10:44 AM
just delete everything from
// Make the onscreen GUI to let the player switch control between Lerpz and the spaceship. function OnGUI () {
to
GUILayout.Label ("Instructions:\nUse the left and right arrow keys to rotate and the up arrow to thrust.");
break;
}
}
Answer by Ashkan_gc · Jun 21, 2010 at 10:50 AM
there are two types of GUIs in unity. if you have function OnGUI () in your code so it's unity GUI and deleting the function and it's content will remove all GUI elements. if the code uses classic GUI then the code is in update and removing the GUI layer from camera will disable it all.
Your answer
Follow this Question
Related Questions
Switch to second camera which has all the GUI 3 Answers
How do i remove the gui windows in my scene 1 Answer
First Person Camera switching 1 Answer
Mouse Orbit + Move Object + Follow Problem 1 Answer
switch player and npc follow player 0 Answers