x


Is there a modulus operator in Unity JavaScript?

is there a mod operator? example c = b%a or c = b mod a e.g., 5%2 = 1

more ▼

asked Aug 21 '10 at 10:06 PM

uni gravatar image

uni
57 7 8 16

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Yes,

if(Time.frameCount%10 == 0)

returns true every 10 frames

more ▼

answered Aug 21 '10 at 10:12 PM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

Sweet. Thanks. I was using it with = overloaded i.e., %=, and got an error.

Aug 21 '10 at 10:18 PM uni
(comments are locked)
10|3000 characters needed characters left

You can. Just Do (a = a % b) because (a %= b) does not work...

more ▼

answered Sep 30 '10 at 09:07 PM

Dansl gravatar image

Dansl
1

(comments are locked)
10|3000 characters needed characters left

If you are looking for a math function though, just use Javascripts %-operator.

Meaning, if you want to calculate number mod 2 use number%2
The value of this operation is the division remainder (9%2 = 1)

more ▼

answered Aug 27 '10 at 08:30 AM

photon gravatar image

photon
2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3446
x38
x5

asked: Aug 21 '10 at 10:06 PM

Seen: 5965 times

Last Updated: Aug 21 '10 at 10:06 PM