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 Poulpc · May 10, 2013 at 02:36 PM · guibuttonkeyboardcontrolsgui button

how to use Gui.Buttons and keyboard ?

my code

 static var level2time : float = 0.0/3;
 var spiller : GameObject;
 var high : int = -100;
 var b : int = 75;
 var h1 :int = 90;
 var h2 :int = 50;
 var h3 :int = 10;
 
 
 function Start () {
 level2time = 0;
 player.playerScore = 0;
 Screen.showCursor = false;
 
 }
 
 function Update () {
 if (player.Quit == true){
 h1 = 90;
 h2 = 50;
 h3 = 10;
 }else{
 h1 = 2290;
 h2 = 2250;
 h3 = 2210;
 }
 if (player.Quit == true){
 Screen.showCursor = true;
 Time.timeScale = 0.0;
 }
 
 if ((player.Quit == false)&& player.paused == false){
 Screen.showCursor = false;
 Time.timeScale = 1.0;
 }
 
 
 
 if(player.paused == true){
 (VolOut());
 }else{
 (Volin());
 }
 
 if(player.playerScore <= 5){
 level2time += Time.deltaTime;
 }
 
 if(player.playerScore >= 6){
      spiller.rigidbody.isKinematic = true;
      player.gameover = true;
         (VolOut());
         if(level2time < PlayerPrefs.GetFloat("level2")){
         PlayerPrefs.SetFloat("level2",level2time);
         PlayerPrefs.SetString("name2",scoremenu.mainname);
         high = 130;
         }
        
      LoadLevel(4, 2.5);
 }
 if(Input.GetKeyDown("m")) {
              if(audio.mute)
                 audio.mute = false;
             else
                 audio.mute = true;
         }
 }
 
 var Design : GUISkin;
 
 function OnGUI () {
 var someString = String.Format("{0:00}:{1:00}", Mathf.Floor(level2time/60), level2time % 60);
 
 GUI.skin = Design;
 GUI.Label(Rect(10,10,200,50),"Level: 2");
 GUI.Label(Rect(10,40,200,50),"Coins: " + player.playerScore);
 GUI.Label(Rect(115,40,200,50),"/6");
 GUI.Label(Rect(10,70,200,50),"Lives: " + player.playerLives);
 GUI.Label(Rect(10,100,200,50),"Timer: " + someString);
 GUI.Label(Rect(10,high,200,50),"New HighScore");
 
 
  if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h1,150,30),"Return To Game")){
             player.q2 = false;
             player.Quit = false;
                  }
 
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h2,150,30),"Main Menu"))
             Application.LoadLevel(0);
             
 
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h3,150,30),"Quit Game")){
             Application.Quit();
 }
 
 }
 
 
 function LoadLevel(level: int, delay: float){
    yield WaitForSeconds(delay);
     Application.LoadLevel(level);
 }
 
 
 function VolOut(){
 while(audio.volume>0.05){
 audio.volume-=0.001;
 yield;
 }
 }
 function Volin(){
 while(audio.volume<0.2){
 audio.volume += 0.001;
 yield;
 }
 }

i am trying to do this

 #pragma strict
 static var level1time : float = 0.0/3;
 var spiller : GameObject;
 var time01 : String;
 var high : int = -100;
 
 var b : int = 75;
 var h1 :int = 90;
 var h2 :int = 50;
 var h3 :int = 10;
 
 var menuOptions = new String[3];
 menuOptions[0] = "Return To Game";
 menuOptions[1] = "Main Menu";
 menuOptions[2] = "Quit Game";
 var selectedIndex = 0;
 
 
 function Start () {
 player.q2 = false;
 level1time = 0;
 player.playerLives = 3;
 player.playerScore = 0;
 Screen.showCursor = false;
 }
 
 
 function Update () {
 if (player.Quit == true){
 h1 = 90;
 h2 = 50;
 h3 = 10;
 }else{
 h1 = 2290;
 h2 = 2250;
 h3 = 2210;
 }
 
 
 if (Input.GetAxis("Vertical")* -1) {
         selectedIndex = menuSelection(menuOptions, selectedIndex, "down");
    }
   if (Input.GetAxis("Vertical")) {
         selectedIndex = menuSelection(menuOptions, selectedIndex, "up");
    }
 
 
 
 if (player.Quit == true){
 Screen.showCursor = true;
 Time.timeScale = 0.0;
 }
 
 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, selectedItem, direction) {
 
   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 () {
 var someString = String.Format("{0:00}:{1:00}", Mathf.Floor(level1time/60), level1time % 60);
 
 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,200,50),"Timer: " + someString);
 GUI.Label(Rect(10,high,200,50),"New HighScore");
 
 GUI.SetNextControlName ("Return To Game");
  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 ("Main Menu");
 if (GUI.Button(Rect(Screen.width/2-b,Screen.height/2-h2,150,30),"Main Menu")){
             Application.LoadLevel(0);
             }
 GUI.SetNextControlName ("Quit Game");
 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 time01 :String;
 min = level1time/60;
 sec = level1time%60;
 time01 = min.ToString()+ ":" + sec.ToString("D2");
 
 
 }
 
 
 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;
 }
 }



but i am getting this errors

Assets/Scripts/score.js(95,36): BCE0019: 'length' is not a member of 'Object'. Assets/Scripts/score.js(97,26): BCE0051: Operator '-' cannot be used with a left hand side of type 'Object' and a right hand side of type 'int'. Assets/Scripts/score.js(101,40): BCE0019: 'length' is not a member of 'Object'. Assets/Scripts/score.js(104,14): BCE0051: Operator '+' cannot be used with a left hand side of type 'Object' and a right hand side of type 'int'.

i am beginder trying the best i can to make my game, i am thankful for eny help

Comment
Add comment · Show 5
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 10, 2013 at 03:58 PM 0
Share

looks good now i only get this error

Assets/Scripts/score.js(91,62): BCE0018: The name 'Integer' does not denote a valid type ('not found'). Did you mean 'System.Runtime.CompilerServices.IndexerNameAttribute'?

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

Ok so i think it's int ins$$anonymous$$d of Integer in my code.

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

i change Integer to int, all work now, thx for the help, i am so happy

avatar image ExTheSea · May 10, 2013 at 04:21 PM 0
Share

I converted my comment to an answer so that you can accept it to mark the question as solved.

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

oki thx again

1 Reply

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

Answer by ExTheSea · May 10, 2013 at 02:48 PM

You have this function

 function menuSelection (menuItems, selectedItem, direction) {

. Like you have it now you don't declare their type so they default to the Object Type. What you have to do is change the part in brackets to something like this:

 function menuSelection (menuItems : String[], selectedItem : int, direction : String) {

Maybe you have to change it a bit when you if you need slightly different types.

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

14 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

Related Questions

How to get a button to act as a keyboard key 1 Answer

GUI.Button's status react to keyboard event? 0 Answers

gui button to work exctly like up arrow key 1 Answer

error with unity button unityengine.rect does t contain 5 contru 2 Answers

gui text button dont work 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