unitytips: Property Patterns

Unity started to supporting C# 8.0 with version 2020.2 beta and now we can start to use some new features like the Property Pattern.

post image


Introduction

Property Patterns enables you to match on properties of the object examined in a Switch Expressions.

The switch expression provides for switch-like semantics in an expression context. It provides a concise syntax when the switch arms produce a value.

Sample

In this sample, we will calculate the damage that an NPC can cause taking into account if it is an enemy, and if it is armed.

Loading comments...
Tutorials

Articles

Labs