- Home /
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
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.
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);