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 hannm · Jan 30, 2014 at 11:41 AM · guimousemenukeylock

menu issue and mouse click

hey guys im making a FPS and im using that Ulimate FPS asset,and i added UniSave into it but because the FPS uses mouse lock i cant access the menu via the mouse when i press is there anyway i can change it so i dont have to use the mouse to highlight the menus i can just use the Keyboard arrow keys to go up and down and Enter to go into that menu that is highlighted on..

the pause menu code is

 using UnityEngine;
 using System;
 
 public class TestGUI : MonoBehaviour 
 {
     public static TestGUI Instance;
     public delegate void GUIState();
     public GUIState CurrentState;
     
     public GUIStyle ButtonStyle = new GUIStyle();
     
     private bool _ingame;
 
     private Vector2 _scrollViewVector = Vector2.zero;
 
     private string[] _selStrings;
     private string _saveFileInfoText;
 
     private int _selectedSaveIndex;
     private int _amountOfElements;
 
     private bool _showDeletePrompt;
     private bool _showOverwritePrompt;
     private bool _showSavingPrompt;
     private bool _showNewSaveWindow;
 
     private string _newSaveName = "";
 
     private string _menuOption;
 
     private bool _refreshSavesList;
 
     public SaveFileInfo[] Saves;
 
     private string _errorMessage;
 
 
     private GUIStyle _textStyle;
     private bool _showSaveCompletedText;
     private DateTime _startTime;
     private DateTime _endTime;
 
     void Awake()
     {
         if (Instance != null && Instance != this)
         {
             Destroy(gameObject);
             return;
         }
 
         Instance = this;
         
         _textStyle = new GUIStyle { fontSize = 26, normal = { textColor = Color.white } };
 
         DontDestroyOnLoad(gameObject);
 
         UniSave.OnLoadingFailed += UniSave_OnLoadingFailed;
         UniSave.OnSavingCompleted += UniSave_OnSavingCompleted;
     }
 
 
     void Start () 
     {
         if (Application.loadedLevelName == "MainMenu")
         {
             CurrentState = MainMenu;
         }
             
         else
         {
             CurrentState = InGame;
         }
     }
     
     void Update () 
     {
         if (_ingame && CurrentState != MainMenu && CurrentState != ErrorPrompt  && Input.GetKeyDown(KeyCode.Escape))
         {
             CurrentState = MainMenu;
         }
     }
     
     private void InGame()
     {
         _ingame = true;
 
         var mouseLook = FindObjectsOfType(typeof(MouseLook));
 
         foreach (MouseLook comp in mouseLook)
         {
             comp.enabled = true;
         }
     }
     
     private void NotInGame()
     {
         _ingame = false;
         CurrentState = MainMenu;
     }
     
     private void MainMenu()
     {
         GUI.BeginGroup(new Rect(Screen.width / 2 - 500, Screen.height / 2 - 95, 320, 425));
 
         if (!_ingame)
         {
             if (GUI.Button(new Rect(0, 0, 200, 25), "New Game"))
             {
                 Application.LoadLevel("TestLevel");
                 CurrentState = InGame;
             }
             
             if (GUI.Button(new Rect(0, 35, 200, 25), "Load Game"))
             {
                 _menuOption = "Load";
                 _refreshSavesList = true;
                 CurrentState = LoadSaveMenu;
             }
             
             if (GUI.Button(new Rect(0, 70, 200, 25), "Quit"))
             {
                 Application.Quit();
             }
         }
 
         else
         {
             var mouseLook = FindObjectsOfType(typeof(MouseLook));
 
             foreach (MouseLook comp in mouseLook)
             {
                 comp.enabled = false;
             }
 
             if (GUI.Button(new Rect(0, 0, 200, 25), "Back to Game"))
             {
                 CurrentState = InGame;
             }
 
             if (GUI.Button(new Rect(0, 35, 200, 25), "Save Game"))
             {
                 _menuOption = "Save";
                 _refreshSavesList = true;
                 CurrentState = LoadSaveMenu;
             }
 
             if (GUI.Button(new Rect(0, 70, 200, 25), "Load Game"))
             {
                 _menuOption = "Load";
                 _refreshSavesList = true;
                 CurrentState = LoadSaveMenu;
             }
 
             if (GUI.Button(new Rect(0, 105, 200, 25), "Quit to Main Menu"))
             {
                 Application.LoadLevel("MainMenu");
                 CurrentState = NotInGame;
             }
         }
 
         GUI.EndGroup();
     }
     
     private void LoadSaveMenu()
     {
         if (_refreshSavesList)
         {
             Saves = UniSave.GetSaves();
             _refreshSavesList = false;
         }
 
         int count = Saves.Length;
         int i = 0;
 
         _selStrings = new string[count];
 
         if (Saves.Length > 0)
         {
            _saveFileInfoText = Environment.NewLine + Saves[_selectedSaveIndex].Name + Environment.NewLine +
                                Saves[_selectedSaveIndex].LevelName + Environment.NewLine +
                                Saves[_selectedSaveIndex].Date;
         }
 
         else
         {
             _saveFileInfoText = "";
         }
 
         GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 297, 300, 75));
         GUI.Box(new Rect(0, 0, 300, 75), _saveFileInfoText);
         GUI.EndGroup();
 
         GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 212, 320, 425));
 
         GUI.Box(new Rect(0, 0, 300, 370), "");
 
         _scrollViewVector = GUI.BeginScrollView(new Rect(0, 10, 320, 350), _scrollViewVector, new Rect(0, 0, 300, 360 + ((_amountOfElements - 5) * 70)), false, false);
 
         _amountOfElements = 0;
 
         foreach (SaveFileInfo save in Saves)
         {
             _selStrings[i] = Environment.NewLine + save.Name + Environment.NewLine + Environment.NewLine;
 
             _amountOfElements++;
 
             i++;
         }
         
         GUILayout.BeginArea(new Rect(10, 0, 280, 350 + ((_amountOfElements - 5) * 70)));
         _selectedSaveIndex = GUILayout.SelectionGrid(_selectedSaveIndex, _selStrings, 1);
         GUILayout.EndArea();
         
         GUI.EndScrollView();
 
         if (_menuOption == "Load")
         {
             if (GUI.Button(new Rect(0, 400, 75, 25), "Load"))
             {
                 if (Saves.Length > 0)
                 {
                     UniSave.Load(Saves[_selectedSaveIndex].Name);
                     CurrentState = InGame;
                 }
             }
 
             if (GUI.Button(new Rect(300 - 75, 400, 75, 25), "Delete"))
             {
                 if (Saves.Length > 0)
                 {
                     if (!_showDeletePrompt)
                     {
                         _showDeletePrompt = true;
                     }
                 }
             }
         }
 
         if (_showDeletePrompt)
         {
             GUILayout.Window(0, new Rect(Screen.width / 2 - (250 + 500), Screen.height / 2 - 100, 500, 200), DeletePrompt, "Are you sure you want to delete \"" + Saves[_selectedSaveIndex].Name + "\"?");
         }
 
         else if (_menuOption == "Save")
         {
             if (GUI.Button(new Rect(0, 400, 75, 25), "New Save"))
             {
                 if (!_showNewSaveWindow)
                 {
                     _showNewSaveWindow = true;
                 }
             }
 
             if (GUI.Button(new Rect(300 - 75, 400, 75, 25), "Overwrite"))
             {
                 if (Saves.Length > 0)
                 {
                     if (!_showOverwritePrompt)
                     {
                         _showOverwritePrompt = true;
                     }
                 }
             }
         }
 
         if (_showNewSaveWindow)
         {
             _showOverwritePrompt = false;
             GUILayout.Window(0, new Rect(Screen.width / 2 - (250 + 500), Screen.height / 2 - 100, 500, 200), NewSaveWindow, "");
         }
 
         if (_showOverwritePrompt)
         {
             _showNewSaveWindow = false;
             GUILayout.Window(0, new Rect(Screen.width / 2 - (250 + 500), Screen.height / 2 - 100, 500, 200), OverwriteWindow, "Are you sure you want to overwrite \"" + Saves[_selectedSaveIndex].Name + "\"?");
         }
 
         GUI.EndGroup();
 
         if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + (212.5f + 20), 75, 25), "Back"))
         {
             CurrentState = MainMenu;
         }
     }
 
     private void DeletePrompt(int windowID)
     {
         if (GUILayout.Button("Yes"))
         {
             UniSave.Delete(Saves[_selectedSaveIndex].Name);
 
             if (_selectedSaveIndex > 0)
             {
                 _selectedSaveIndex -= 1;
             }
 
             _refreshSavesList = true;
             _showDeletePrompt = false;
         }
 
         else if (GUILayout.Button("No"))
         {
             _showDeletePrompt = false;
         }
     }
 
     private void OverwriteWindow(int windowID)
     {
         if (GUILayout.Button("Yes"))
         {
             UniSave.Save(Saves[_selectedSaveIndex].Name);
             _showOverwritePrompt = false;
         }
 
         else if (GUILayout.Button("No"))
         {
             _showOverwritePrompt = false;
         }
     }
 
     private void NewSaveWindow(int windowID)
     {
         _newSaveName = GUILayout.TextField(_newSaveName, 200);
 
         if (GUILayout.Button("Save"))
         {
             if (!String.IsNullOrEmpty(_newSaveName))
             {
                 UniSave.Save(_newSaveName);
                 _newSaveName = "";
                 _showNewSaveWindow = false;
                 //_showSavingPrompt = true;
             }
         }
 
         if (GUILayout.Button("Cancel"))
         {
             _showNewSaveWindow = false;
         }
     }
 
     private void ErrorPrompt()
     {
         GUI.Box(new Rect(0, Screen.height / 2 - 100, Screen.width, 50), "Loading failed:" + Environment.NewLine + _errorMessage);
 
         if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 + 75, 100, 50), "Back"))
         {
             Destroy(Loading.Instance.gameObject);
             Application.LoadLevel("Menu");
             _ingame = false;
             CurrentState = MainMenu;
         }
     }
     
     void OnGUI()
     {
         GUI.skin.button = ButtonStyle;
     
         CurrentState();
 
         while (UniSave.IsSaving)
         {
             GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 20, 100, 40), "Saving...", _textStyle);
         }
 
         if (_showSaveCompletedText)
         {
             TimeSpan duration = DateTime.Now - _startTime;
 
             if (duration.Seconds < 4)
             {
                 GUI.Label(new Rect(Screen.width / 2 - 75, Screen.height / 2 - 20, 150, 40), "Game Saved", _textStyle);
                 _refreshSavesList = true;
             }
 
             else
             {
                 _showSaveCompletedText = false;
             }
         }
     }
 
     private void UniSave_OnLoadingFailed(Exception exception)
     {
         _errorMessage = exception.Message;
         CurrentState = ErrorPrompt;
     }
 
     private void UniSave_OnSavingCompleted()
     {
         _startTime = DateTime.Now;
         _showSaveCompletedText = true;
     }
 }






thanks guys :)

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

0 Replies

· Add your reply
  • Sort: 

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

changing from mouse click to keys 0 Answers

FPC Mouselook Axis problem on pause GUI 1 Answer

Loading GUI in middle of mouse and make it work radial 1 Answer

turn off script with a key.. 1 Answer

Locking cursor without changing position 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