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 berting01 · Feb 19, 2012 at 08:25 AM · guirandom.rangerandomize

how to satisfy this code

I have made a version of mine of the binary game. what I want to do is when I click the answer1 button, it will add the value of the 8 buttons. If the answer is equal to the randomized number, it will generate again a random number. In my case, it does not generate a number.. what should be the problem? heres the code :

private var startTime;

private var restSeconds : int;

private var roundedRestSeconds : int;

private var displaySeconds : int;

private var displayMinutes : int;

var button1;

var button2;

var button3;

var button4;

var button5;

var button6;

var button7;

var button8;

var answer1;

var countDownSeconds : int;

var decimal;

var screenW;

function Update(){

screenW=Screen.currentResolution.width;

if(answer1==decimal){

     decimal=decimal=Random.Range(1, 128);

     }

}

function Start()

{ button1=1;

  button2=1;

  button3=1;

  button4=1;

  button5=1;

  button6=1;

   button7=1;

  button8=1;

 decimal= Random.Range(1, 128);

}

function OnGUI(){

//first button line

 GUI.Label(Rect(10,0,100,30),"128");

 if(GUI.Button(Rect(10,20,100,100),button1.ToString())){

     if(button1==1){

         button1=0;

     }

     else if(button1==0){

         button1=1;

     }

 }

 GUI.Label(Rect(110,0,100,30),"64");

 if(GUI.Button(Rect(110,20,100,100),button2.ToString())){

     if(button2==1){

         button2=0;

     }

     else if(button2==0){

         button2=1;

     }

 }

 GUI.Label(Rect(210,0,100,30),"32");

 if(GUI.Button(Rect(210,20,100,100),button3.ToString())){

     if(button3==1){

         button3=0;

     }

     else if(button3==0){

         button3=1;

     }

 }

 GUI.Label(Rect(310,0,100,30),"16");

 if(GUI.Button(Rect(310,20,100,100),button4.ToString())){

 

 if(button4==1){

         button4=0;

     }

     else if(button4==0){

         button4=1;

     }

 

 }

 GUI.Label(Rect(410,0,100,30),"8");

 if(GUI.Button(Rect(410,20,100,100),button5.ToString())){

     if(button5==1){

         button5=0;

     }

     else if(button5==0){

         button5=1;

     }

 }

 GUI.Label(Rect(510,0,100,30),"4");

 if(GUI.Button(Rect(510,20,100,100),button6.ToString())){

     if(button6==1){

         button6=0;

     }

     else if(button6==0){

         button6=1;

     }

 }

 GUI.Label(Rect(610,0,100,30),"2");

 if(GUI.Button(Rect(610,20,100,100),button7.ToString())){

     if(button7==1){

         button7=0;

     }

     else if(button7==0){

         button7=1;

     }

 }

 GUI.Label(Rect(710,0,100,30),"1");

 if(GUI.Button(Rect(710,20,100,100),button8.ToString())){

     if(button8==1){

         button8=0;

     }

     else if(button8==0){

         button8=1;

     }

 }

 

 GUI.Label(Rect(820,50,100,100),"=");

 GUI.Button(Rect(900,20,100,100),decimal.ToString());

 if(GUI.RepeatButton(Rect(1000,20,100,100),"answer1")){

     answer1=button1+button2+button3+button4+button5+button6+button7+button8;

     

 }

 

    //make sure that your time is based on when this script was first called

 //instead of when your game started

 var guiTime = Time.time - startTime;



 restSeconds = countDownSeconds - (guiTime);



 //display messages or whatever here -->do stuff based on your timer

 if (restSeconds <0) {

     countDownSeconds=10;

     startTime=Time.time;

     print ("Time is Over");

    

     //do stuff here

 }



 //display the timer

 roundedRestSeconds = Mathf.CeilToInt(restSeconds);

 displaySeconds = roundedRestSeconds % 60;

 displayMinutes = roundedRestSeconds / 60; 



 text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds); 

 GUI.Label(Rect(screenW-200,25,100,100), "nextline:");

 GUI.Label (Rect (screenW-100, 25, 100, 30), text);

}

function Awake() {

 startTime = Time.time;

}

I hope that you can help me.. thanks

Comment
Add comment · Show 1
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 Eric5h5 · Feb 19, 2012 at 08:57 AM 1
Share

When posting code, please take a couple of seconds to format it properly. Also try reducing it to the relevant parts...personally I won't bother to look at large amounts of unformatted code.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by BiG · Feb 19, 2012 at 08:59 AM

I haven't read all your code, but this is weird:

 decimal=decimal=Random.Range(1, 128);
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

7 People are following this question.

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

Related Questions

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

Setting Scroll View Width GUILayout 1 Answer

Are there better ways to create random behavior? 1 Answer

Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers

how to "blink" more often? 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