Right, i’m back again with another issue - this time with my score counters. I’m using an individual gameobject for each number on the score counter, each is a GUI texture. I was told in another topic that if (10 % variable) for example checks if the variable is a multiple of 10. If this is wrong, please correct me. To make solving the problem a bit more fun, think of it as a puzzle.
Abducting a cow adds 10 points to the score, abducting a human adds 15 points to the score. If either of them are abducted, the Units score counter (the number on the end) goes to 5, and stays 5 no matter how many you abduct. Here is the script:
var number0 : Texture2D;
var number5 : Texture2D;
function Update ()
{
if (10 % (ScoreCount.score + 5))
{
guiTexture.texture = number5;
}
else
{
guiTexture.texture = number0;
}
}
What have i done wrong? D: As far as i can see that is asking - “if the score +5 is a variable of 10, change the GUI number to 5. else, make it 0.” - is that right?
lots of love and thanks in advance -
<>FreakFish<><
You have the modulo % backwards. It returns the remainder after division, so you keep dividing 10 by your variable and getting that remainder but you need the opposite:
if (variable % 10 == 0) //divisible by 10 because the remainder is 0
See if that helps you.
Thanks for the fast reply, here is the updated script:
var number0 : Texture2D;
var number5 : Texture2D;
function Update ()
{
if (ScoreCount.score + 5 % 10 == 0)
{
guiTexture.texture = number5;
}
else
{
guiTexture.texture = number0;
}
}
now no matter what or how much i abduct it stays at zero, which means the if statement is not true. I’ve done something wrong, right?
Maybe you should try adding ( ).
((ScoreCount.score + 5) % 10)
Success!
var number0 : Texture2D;
var number5 : Texture2D;
function Update ()
{
if ((ScoreCount.score + 5) % 10 == 0)
{
guiTexture.texture = number5;
}
else
{
guiTexture.texture = number0;
}
}
Problem seemingly solved! If my other script doesn’t work I may come back to have it corrected, but thank you very much!
right, sadly my Tens script isnt working
would you be so kind as to point out what i’ve done wrong? i set it out like the units one;
var number0 : Texture2D;
var number1 : Texture2D;
var number2 : Texture2D;
var number3 : Texture2D;
var number4 : Texture2D;
var number5 : Texture2D;
var number6 : Texture2D;
var number7 : Texture2D;
var number8 : Texture2D;
var number9 : Texture2D;
function Update ()
{
if (ScoreCount.score == 0)
{
guiTexture.texture = number0;
}
else
{
if ((ScoreCount.score + 5) % 100)
{
guiTexture.texture = number9;
}
if ((ScoreCount.score + 10) % 100)
{
guiTexture.texture = number9;
}
if ((ScoreCount.score + 15) % 100)
{
guiTexture.texture = number8;
}
if ((ScoreCount.score +20) % 100)
{
guiTexture.texture = number8;
}
if ((ScoreCount.score + 25) % 100)
{
guiTexture.texture = number7;
}
if ((ScoreCount.score + 30) % 100)
{
guiTexture.texture = number7;
}
if ((ScoreCount.score + 35) % 100)
{
guiTexture.texture = number6;
}
if ((ScoreCount.score + 40) % 100)
{
guiTexture.texture = number6;
}
if ((ScoreCount.score + 45) % 100)
{
guiTexture.texture = number5;
}
if ((ScoreCount.score + 50) % 100)
{
guiTexture.texture = number5;
}
if ((ScoreCount.score + 55) % 100)
{
guiTexture.texture = number4;
}
if ((ScoreCount.score + 60) % 100)
{
guiTexture.texture = number4;
}
if ((ScoreCount.score + 65) % 100)
{
guiTexture.texture = number3;
}
if ((ScoreCount.score + 70) % 100)
{
guiTexture.texture = number3;
}
if ((ScoreCount.score + 75) % 100)
{
guiTexture.texture = number2;
}
if ((ScoreCount.score + 80) % 100)
{
guiTexture.texture = number2;
}
if ((ScoreCount.score + 85) % 100)
{
guiTexture.texture = number1;
}
if ((ScoreCount.score + 90) % 100)
{
guiTexture.texture = number1;
}
if ((ScoreCount.score + 95) % 100)
{
guiTexture.texture = number0;
}
if ((ScoreCount.score + 100) % 100)
{
guiTexture.texture = number0;
}
}
}
i look forward to seeing more of your wisdom!
ah of course, the == 0 at the end! how forgetful am i…