coding22 coding22 - 2 years ago 60
Swift Question

How do I increment the score by 10 when a user collects a coin in Swift?

Right now its going up by 1 but I need it to go up by 10 whenever a coin is collected. How do I do that? I tried doing it this way self.score + 10
but that didn't work. Thanks! If you need more code or info let me know!!

if firstBody.categoryBitMask == HeroCategory && sixthBody.categoryBitMask == CoinCategory {


Answer Source

To increment a value by 10, use:

self.score += 10

See the documentation for Compound Assignment Operators for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download