Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by Skjalg · Feb 08, 2010 at 05:45 PM · guigamepadhudxbox360

XBox 360 controller for the GUI

I have followed the Lerpz tutorial on how to make a Start Menu for my game, but when I load up the game with my xbox 360 controller there is now way for me to select the buttons that I have made.

How can I make this work?

I have attached the code I've been using. Just attach it to your camera if you want to see how it behaves.

using UnityEngine; using System.Collections;

[AddComponentMenu("ESE Interface/Manu Menu GUI")] public class MainMenuGUI : MonoBehaviour { public GUISkin GuiSkin; private bool isLoading = false; public string nameOfFirstLevel = "level_01"; public string nameOfContinueLevel = "continueLevel"; public string nameOfCreditsLevel = "credits"; public bool showContinueButton = true;

 public float nativeVerticalResolution = 1900.0f;
 public float nativeHorizontalResolution = 1200.0f;

 public float buttonWidth = 512.0f;
 public float buttonHeight = 170.0f;

 public float buttonGap = 48.0f;
 public float buttonPaddingX = 128.0f;
 public float buttonPaddingY = 512.0f;

 public float exitbuttonSpaceGab = 512.0f;

 public Texture2D loadingScreen;

 public void OnGUI()
 {
     if (GuiSkin)
     {
         GUI.skin = GuiSkin;
     }
     else
     {
         Debug.LogError("MainMenuGUI : GUI Skin object missing!");
     }
     if (!isLoading)
     {
         Vector3 pos = new Vector3(0.0f, 0.0f, 0.0f);
         Vector3 scale = new Vector3(Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1);
         GUI.matrix = Matrix4x4.TRS(pos, Quaternion.identity, scale);


         float scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width;
         float scaledResolutionHeight = nativeHorizontalResolution / Screen.height * Screen.width;
         GUI.BeginGroup(new Rect(0, 0, scaledResolutionHeight, nativeVerticalResolution));
         {
             float left = buttonPaddingX;
             float top = buttonPaddingY;

             if (showContinueButton)
             {
                 MakeButton(left, top, "Continue", nameOfContinueLevel);
             }
             top = top + buttonHeight + buttonGap;
             MakeButton(left, top, "New Game", nameOfFirstLevel);
             top = top + buttonHeight + buttonGap;
             MakeButton(left, top, "Load Game", "Level_01");
             top = top + buttonHeight + buttonGap;
             MakeButton(left, top, "Credits", nameOfCreditsLevel);
             top = top + buttonHeight + exitbuttonSpaceGab;
             MakeExitButton(left, top);

         }
         GUI.EndGroup();
     }

     if (isLoading)
     {
         GUIStyle backgroundStyle = new GUIStyle();
         backgroundStyle.normal.background = loadingScreen;
         GUI.Label (new Rect( ( Screen.width - (Screen.height * 2)) * 0.75f, 0, Screen.height * 2, Screen.height), "", backgroundStyle);
     }
 }

 private void MakeExitButton(float left, float top)
 {
     bool isWebPlayer = (Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer);
     if (!isWebPlayer)
     {
         if (GUI.Button(new Rect(left, top, buttonWidth, buttonHeight), "Exit")) Application.Quit();
     }
 }

 private void MakeButton(float left, float top, string name, string levelToLoad)
 {
     if (GUI.Button(new Rect(left, top, buttonWidth, buttonHeight), name))
     {
         isLoading = true;
         Application.LoadLevel(levelToLoad);
     }
 }

}

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

1 Reply

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

Answer by naruse · Feb 10, 2010 at 10:04 AM

Hi,

To make a control work with a GUI interface is a little more difficult.

What I would do is detect the key presses from your xbox controller and then with GUI.FocusControl focus the GUI controls you have selected.

Hope it helps! ;)

Comment
Add comment · Show 3 · 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 Skjalg · Feb 13, 2010 at 08:34 PM 0
Share

I manage to scroll the buttons with the use of the controller by using GUI.FocusControl but how can I press the buttons?

avatar image name111 · Sep 25, 2010 at 01:51 AM 0
Share

do you $$anonymous$$d telling me the new script you have? ive also been trying to get this done

avatar image Majmuns · Jul 05, 2011 at 02:45 AM 0
Share

I would also like to know, once using GUI.FocusControl has been invoked, how do you actually selected the focused button?

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problems with GUI and Resolutions. (C#) 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Is there anyway to only show a part of a GUI image during the game? (C#) 1 Answer

GUI Help, timer and counter 1 Answer


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