Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Biendeo · Jun 21, 2010 at 10:31 AM · cameraguifollowswitchremove

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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;
    }
}
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges