I want to spawn a game object every time a public variable is 5 more than the last for example 5,10,15,20… but how can I do this? I was thinking of making something like
public var i:int;
but the problem is that this is suppose to go to infinity so how can I?maybe a list? or and array?
Think of your problems in terms of the sequence itself. When do you want the
if statement to execute? You want it to execute when
i is a multiple of
If you do a quick google search you will find that finding out whether a variable is a multiple of some number is quite easily done using the
The modulus operator returns the remainder of the left hand side, when divided by the right hand side. In almost every language, the modulus operator is
2 % 10 = 2 and
20 % 8 = 4.
Back to the problem, what is the remainder when something is exactly divisible by a number?
So your test is really easy to do:
i % 5 == 0