- Home /
This question was
closed Jun 28, 2020 at 08:30 AM by
afdal27kk for the following reason:
Too subjective and argumentative
problem adding element of array
i have array call apple, i just using simple loop to add apple to element so i set max apple each element is 10, i just add 27 apple so the element sould be element 0 = 10, element 1 = 10, element 2 = 7, but when i remove apple on element 1 to 0 the script is adding into element 1 not complete until element 2 is full i thing is because a loop
if (Input.GetKeyDown(KeyCode.E))
{
// Add apple
for (int i = 0; i < apple.Length; i++)
{
if (apple[i] < 10)
{
apple[i]++;
break;
}
}
}
so how can i to add apples that are less than the maximum limit before the empty element ??, please help,,
apel.png
(3.6 kB)
Comment
Answer by Bunny83 · Jun 28, 2020 at 07:57 AM
I don't see any issue with the code you have posted so far. Are you sure there is no other code messing with the "apples" array?