- Home /
Number once decrease
Hi, i am newbie, but have some experience, i am making some study expamples for me, i making money decreasing or increase when is the other number selected i already made number with random range when i press A the number change (0,10) and i make a money and when is the number one selected money decrease by hundred, but the hundred decrease per second of my money and i want make this when i press A the money will be decrease by hundred 1000-100=900 how can i make it ? there is the code:
var number : int;
var money: float;
function Start() {
number = Random.Range(1,10);
money = 1000;
}
function Update() {
if (Input.GetKeyDown(KeyCode.A)){
number = Random.Range(1,10);
}
if (number == 1){
money -= 100;
}
}
function OnGUI() {
GUI.Label(Rect(10,50,100,300), "Money: " + money);
GUI.Label(Rect(10,10,100,300), "The number that was generated: " + number);
if(number >=5){
GUI.Label(Rect(180,10,100,300), "Bad");
} else {
GUI.Label(Rect(180,10,100,300), "Nice");
}
}
Answer by tanoshimi · Dec 18, 2014 at 10:58 PM
So you only want to subtract money (with 1 in 9 chance) in the frame in which they was pressed? Try:
function Update() {
if (Input.GetKeyDown(KeyCode.A)){
number = Random.Range(1,10);
if (number == 1){
money -= 100;
}
}
}
Your answer
Follow this Question
Related Questions
How can i randomly increase/decrease a value over time? 1 Answer
How to Make a Vertical-Scroll Number Input Field, i.e. < > Value Amount 0 Answers
Making Money 1 Answer
money counter with thousand separators? 2 Answers
Assets Question 0 Answers