- Home /
How do i add 1 to a value?
if the player gets 500xp, 10xp a kill then he gets 1 credit how to make the value of Credit which by default is 0 i want to change it to 1 if the certain xp is achieved! thanks unity Answers!
static var Credit : int; var xp : int = 0; function Update () {
if(xp == 100){
Credit = 1;
}
if(xp == 800){
Credit = 1;
}
if(xp == 1500){
Credit = 1;
}
if(xp == 2100){
Credit = 1;
}
if(xp == 2800){
Credit = 1;
}
if(xp == 3100){
Credit = 1;
}
if(xp == 3800){
Credit = 1;
}
if(xp == 4000){
Credit = 1;
}
Answer by Karsnen_2 · Jan 13, 2013 at 12:49 AM
i seriously do not understand your question.
But from what I understood,
you have one counter, xp -> which values the hit points etc.
Credit is added up for every kill.
if you want a counter for total credits and if you want that counter to be summed for every kill then,
var TotalCredit : int;
// Call this function whenever you want to add credits to it.
//AddCredit();
// Function to add credits
function AddCredit ()
{
TotalCredit++;
}
Answer by Owen-Reynolds · Jan 13, 2013 at 04:18 AM
Credit = Credit + 1;
is the way to increase it by one. BUT, the rest of it is way off. It probably shouldn't be in Update; == won't work (what if you go from 790 exp to 840?) and it needs a way to give each exp bonus only 1 time.
The thing is, adding one is such a basic thing that I'd recommend looking through some of the "How do I learn Programming" threads here.