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
1
Question by Poulpc · May 31, 2013 at 02:01 PM · menu

D-pad navigate menu ??

i am looking for a GetAxisDown function, i have tryed a lot of ways to do it, but i can´t get it to work

i am trying to add the D-pad to my menu system, the problem is, it speeds through the menu, here is a video of it http://www.youtube.com/watch?v=1THQ54DCOVQ

on Pc javascript and Time.timeScale = 0.0

 #pragma strict
 static var level1time : float = 0.0/3;
 var spiller : GameObject;
 var someString : String;
 var high : int = -100;
 var menuup:boolean;
 var menudown:boolean;
 var b : int = 75;
 var h1 :int = 90;
 var h2 :int = 50;
 var h3 :int = 10;
 
 var menuOptions = new String[3];
 menuOptions[0] = "menu01";
 menuOptions[1] = "menu02";
 menuOptions[2] = "menu03";
 
 var selectedIndex = 0;
 
 
 function Start () {
 
 menuup = false;
 menudown = false;
 player.q2 = false;
 level1time = 0;
 player.playerLives = 3;
 player.playerScore = 0;
 Screen.showCursor = false;
 }
 
 
 function Update () {
 showtime();
 
 
 
 if (Input.GetAxis("axis7") == 0){
 menudown = false;
 }
 if (menudown == false && Input.GetAxis("axis7") > 0)
         {
             menudown = true;
             return false;
         }
 
 
 
 
 if (player.Quit == true){
 h1 = 90;
 h2 = 50;
 h3 = 10;
 }else{
 h1 = 2290;
 h2 = 2250;
 h3 = 2210;
 }
 
 
 if (player.Quit == false){
 if ((Input.GetButtonDown("Fire1"))|| (Input.GetButtonDown("Fire2"))){
 player.q2esc();
       player.Quit = true;
       }
 }
 
 
 
 
 if (player.Quit == true){
 Screen.showCursor = true;
 Time.timeScale = 0.0;
 
 
 if (Input.GetKeyDown("up")|| (menuup == true)|| (Input.GetKeyDown("w"))) {
         selectedIndex = menuSelection(menuOptions, selectedIndex, "up");
         
    }
 if (Input.GetKeyDown("down")|| (menudown == true)|| (Input.GetKeyDown("s"))) {
         selectedIndex = menuSelection(menuOptions, selectedIndex, "down");
         
    }
 
 
 if ((Input.GetKeyDown("space"))||(Input.GetKey ("return"))|| (Input.GetButtonDown("Jump"))){
  selectedIndex = menuSelection(menuOptions, selectedIndex, "enter");
  player.Quit = false;
  player.paused = false;
 }
 
 }
 
 if ((player.Quit == false)&& player.paused == false){
 Screen.showCursor = false;
 Time.timeScale = 1.0;
 }
 
 if(player.paused == true){
 (VolOut());
 }else{
 (Volin());
 }
 
 if(player.playerScore <= 4){
 level1time += Time.deltaTime;
 }
 
 if(player.playerScore >= 5){
       spiller.rigidbody.isKinematic = true;
       player.gameover = true;
        (VolOut());
         if(level1time < PlayerPrefs.GetFloat("level1")){
         PlayerPrefs.SetFloat("level1",level1time);
         PlayerPrefs.SetString("name1",scoremenu.mainname);
         high = 130;
         }
                 
      LoadLevel(3, 2.5);
 }
 if(Input.GetKeyDown("m")) {
              if(audio.mute)
                 audio.mute = false;
             else
                 audio.mute = true;
         }
     }
     
 function menuSelection (menuItems : String[], selectedItem : int, direction : String) {
 
 
 if (direction == "enter") {
        if (selectedItem == 0) {
             player.q2 = false;
             player.Quit = false;
             }else if 
             (selectedItem == 1){
             Application.LoadLevel(0);
             }else if
             (selectedItem == 2){
             Application.Quit();
             
           
              
 }
 }
 
 
   if (direction == "up") {
        if (selectedItem == 0) {
         selectedItem = menuItems.length - 1;
        } else {
             selectedItem -= 1;
        }
   }
     if (direction == "down") {
        if (selectedItem == menuItems.length - 1) {
           selectedItem = 0;
           
           
 } else {
 
 selectedItem += 1;
 }
 
   }
   return selectedItem;
   
 }
 
 var Design : GUISkin;
 
 function OnGUI () {
 
 GUI.skin = Design;
 GUI.Label(Rect(10,10,200,50),"Level: 1");
 GUI.Label(Rect(10,40,200,50),"Coins: " + player.playerScore);
 GUI.Label(Rect(115,40,200,50),"/5");
 GUI.Label(Rect(10,70,200,50),"Lives: " + player.playerLives);
 GUI.Label(Rect(10,100,300,50),"Timer: " + someString);
 GUI.Label(Rect(10,high,200,50),"New HighScore");
 
 
 GUI.SetNextControlName ("menu01");
  if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h1,150,30),"Return To Game")){
             player.q2 = false;
             player.Quit = false;
                  }
 GUI.SetNextControlName ("menu02");
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h2,150,30),"Main Menu")){
             Application.LoadLevel(0);
             
             }
 GUI.SetNextControlName ("menu03");
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h3,150,30),"Quit Game")){
             Application.Quit();
             
 }
 GUI.FocusControl (menuOptions[selectedIndex]);
 }
 function showtime(){
 var min:int;
 var sec:int;
 var fra:int;
 var time01 :String;
 min = level1time/60;
 sec = level1time%60;
 fra = level1time * 1000;
 fra = fra % 1000;
 
 someString = String.Format("{0:00}:{1:00}.{2:000}", min, sec,fra);
 }
 
 
 function PlayerCompletedGame() {
     guiText.text = Time.timeSinceLevelLoad.ToString();
 }
 
 
 
 function LoadLevel(level: int, delay: float){
   // wait the delay time...
   yield WaitForSeconds(delay);
   // then load the level:
   Application.LoadLevel(level);
 }
 
 
 function fadeOut(){
 audio.volume -= 0.05 * Time.deltaTime;
 yield WaitForSeconds(0.1);
 audio.volume -= 0.05 * Time.deltaTime;
 yield WaitForSeconds(0.1);
 audio.volume -= 0.05 * Time.deltaTime;
 }
 function VolOut(){
 while(audio.volume>0.05){
 audio.volume-=0.001;
 yield;
 }
 }
 function Volin(){
 while(audio.volume<0.2){
 audio.volume += 0.001;
 yield;
 }
 }
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

3 Replies

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

Answer by Poulpc · May 31, 2013 at 05:18 PM

its not pretty, but it works

 static var level1time : float = 0.0/3;
 var spiller : GameObject;
 var someString : String;
 var high : int = -100;
 var menuup:boolean;
 var menudown:boolean;
 var b : int = 75;
 var h1 :int = 90;
 var h2 :int = 50;
 var h3 :int = 10;
 
 var menuOptions = new String[3];
 menuOptions[0] = "menu01";
 menuOptions[1] = "menu02";
 menuOptions[2] = "menu03";
 
 var selectedIndex = 0;
 
 
 function Start () {
 
 menuup = false;
 menudown = false;
 player.q2 = false;
 level1time = 0;
 player.playerLives = 3;
 player.playerScore = 0;
 Screen.showCursor = false;
 }
 
 function menu (t:float){
 menudown = false;
 yield;
 yield;
 yield;
 yield;
 yield;
 menudown = true;
 yield;
 menudown = false;
  
 }
 
 function menu2 (t:float){
 menuup = false;
 yield;
 yield;
 yield;
 yield;
 yield;
 menuup = true;
 yield;
 menuup = false;
 
 }
 
 function Update () {
 
 showtime();
 
 
 
 if (Input.GetAxis("axis7") == 0){
 menudown = false;
 menuup = false;
 }
 if (menudown == false && Input.GetAxis("axis7") < 0)
         {
         var t = Time.realtimeSinceStartup;
         menu(t);
           
         }
 
 if (menuup == false && Input.GetAxis("axis7") > 0)
         {
         menu2(t);
           
         }
 
 
 if (player.Quit == true){
 h1 = 90;
 h2 = 50;
 h3 = 10;
 }else{
 h1 = 2290;
 h2 = 2250;
 h3 = 2210;
 }
 
 
 if (player.Quit == false){
 if ((Input.GetAxis("axis7") > 0)|| (Input.GetAxis("axis7") < 0)){
 player.q2esc();
       player.Quit = true;
       }
 }
 
 
 
 
 if (player.Quit == true){
 Screen.showCursor = true;
 Time.timeScale = 0.0;
 
 
 if (Input.GetKeyDown("up")|| (menuup == true)|| (Input.GetKeyDown("w"))) {
         selectedIndex = menuSelection(menuOptions, selectedIndex, "up");
         
    }
 if (Input.GetKeyDown("down")|| (menudown == true)|| (Input.GetKeyDown("s"))) {
         selectedIndex = menuSelection(menuOptions, selectedIndex, "down");
         
    }
 
 
 if ((Input.GetKeyDown("space"))||(Input.GetKey ("return"))|| (Input.GetButtonDown("Jump"))){
  selectedIndex = menuSelection(menuOptions, selectedIndex, "enter");
  player.Quit = false;
  player.paused = false;
 }
 
 }
 
 if ((player.Quit == false)&& player.paused == false){
 Screen.showCursor = false;
 Time.timeScale = 1.0;
 }
 
 if(player.paused == true){
 (VolOut());
 }else{
 (Volin());
 }
 
 if(player.playerScore <= 4){
 level1time += Time.deltaTime;
 }
 
 if(player.playerScore >= 5){
       spiller.rigidbody.isKinematic = true;
       player.gameover = true;
        (VolOut());
         if(level1time < PlayerPrefs.GetFloat("level1")){
         PlayerPrefs.SetFloat("level1",level1time);
         PlayerPrefs.SetString("name1",scoremenu.mainname);
         high = 130;
         }
                 
      LoadLevel(3, 2.5);
 }
 if(Input.GetKeyDown("m")) {
              if(audio.mute)
                 audio.mute = false;
             else
                 audio.mute = true;
         }
     }
     
 function menuSelection (menuItems : String[], selectedItem : int, direction : String) {
 
 
 if (direction == "enter") {
        if (selectedItem == 0) {
             player.q2 = false;
             player.Quit = false;
             }else if 
             (selectedItem == 1){
             Application.LoadLevel(0);
             }else if
             (selectedItem == 2){
             Application.Quit();
             
           
              
 }
 }
 
 
   if (direction == "up") {
        if (selectedItem == 0) {
         selectedItem = menuItems.length - 1;
        } else {
             selectedItem -= 1;
        }
   }
     if (direction == "down") {
        if (selectedItem == menuItems.length - 1) {
           selectedItem = 0;
           
           
 } else {
 
 selectedItem += 1;
 }
 
   }
   return selectedItem;
   
 }
 
 var Design : GUISkin;
 
 function OnGUI () {
 
 GUI.skin = Design;
 GUI.Label(Rect(10,10,200,50),"Level: 1");
 GUI.Label(Rect(10,40,200,50),"Coins: " + player.playerScore);
 GUI.Label(Rect(115,40,200,50),"/5");
 GUI.Label(Rect(10,70,200,50),"Lives: " + player.playerLives);
 GUI.Label(Rect(10,100,300,50),"Timer: " + someString);
 GUI.Label(Rect(10,high,200,50),"New HighScore");
 
 
 GUI.SetNextControlName ("menu01");
  if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h1,150,30),"Return To Game")){
             player.q2 = false;
             player.Quit = false;
                  }
 GUI.SetNextControlName ("menu02");
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h2,150,30),"Main Menu")){
             Application.LoadLevel(0);
             
             }
 GUI.SetNextControlName ("menu03");
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h3,150,30),"Quit Game")){
             Application.Quit();
             
 }
 GUI.FocusControl (menuOptions[selectedIndex]);
 }
 function showtime(){
 var min:int;
 var sec:int;
 var fra:int;
 var time01 :String;
 min = level1time/60;
 sec = level1time%60;
 fra = level1time * 1000;
 fra = fra % 1000;
 
 someString = String.Format("{0:00}:{1:00}.{2:000}", min, sec,fra);
 }
 
 
 function PlayerCompletedGame() {
     guiText.text = Time.timeSinceLevelLoad.ToString();
 }
 
 
 
 function LoadLevel(level: int, delay: float){
   // wait the delay time...
   yield WaitForSeconds(delay);
   // then load the level:
   Application.LoadLevel(level);
 }
 
 
 function fadeOut(){
 audio.volume -= 0.05 * Time.deltaTime;
 yield WaitForSeconds(0.1);
 audio.volume -= 0.05 * Time.deltaTime;
 yield WaitForSeconds(0.1);
 audio.volume -= 0.05 * Time.deltaTime;
 }
 function VolOut(){
 while(audio.volume>0.05){
 audio.volume-=0.001;
 yield;
 }
 }
 function Volin(){
 while(audio.volume<0.2){
 audio.volume += 0.001;
 yield;
 }
 }
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 S3dition · May 31, 2013 at 02:16 PM

At a glance, maybe you should yield for x time here:

 if (menudown == false && Input.GetAxis("axis7") > 0)
         {
             menudown = true;
             return false;
         }

Something like:

 if (menudown == false && Input.GetAxis("axis7") > 0)
         {
             menudown = true;
 return yield new WaitForSeconds(0.25f); //sorry, don't recall java version
             return false;
         }

Basically the idea is to wait x seconds before switching menudown to allow the cursor movement on the menu.

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 Poulpc · May 31, 2013 at 03:54 PM 0
Share

Script error: Update() can not be a coroutine.

i can`t use yield ind Update ()

avatar image S3dition · May 31, 2013 at 04:02 PM 0
Share

No, you'll need to use a new method and call it from update. It would work similar to what you have now, but you'll need something like:

     Function Update(){
     
     //...
     
     StartCoroutine($$anonymous$$ove$$anonymous$$enuDown());
     
     }

And then:

     function $$anonymous$$ove$$anonymous$$enuDown(){
     
     if (menudown == false && Input.GetAxis("axis7") > 0)
             {
                 menudown = true;
     yield WaitForSeconds(0.25f); //sorry, don't recall java version
                 return false;
             }
     }

That's not tested, but it should move you in the right direction. Basically, you want your code to refuse to take any more movement input on the menu for x amount of time. How much time will depend on your menu and what you think makes a smooth transition. You'll have to experiment until you find the best amount of time to wait.

avatar image Poulpc · May 31, 2013 at 04:10 PM 0
Share

yes, only problem i have now it that Time.timeScale = 0.0, os i can`t use WaitForSeconds

avatar image
0

Answer by JonathanGeoCox · May 31, 2013 at 02:14 PM

Some controller interfaces don't seem to handle KeyUps and KeyDowns correctly (e.g., Ouya). Since your code is running in Update and the ButtonDown code appears to be being interpreted as simply Button, it being called once each frame. You'll have to add in your own bool checks to control ButtonUp and ButtonDown behavior, or add a timer so that the code can only get called once every so often.

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

15 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

Related Questions

boolean flicker 3 Answers

How to make a Main Menu 3 Answers

GUI Not Showing up? 2 Answers

One GameObjects Script Activating Another GameObjects Script 1 Answer

GUI Menu Display Help 2 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