The C# Rigidbody2DExtension script class adds a new method called AddExlosionForce(...) to all Rigidbody2D components in the project. The advantage of using an extension class method is that this method now becomes available to use by all other scripts in the project, with no need to refer to this extension class explicitly – it's as if Unity provided this extra method as part of its core code library.
This AddExlosionForce(...) method takes three parameters when called:
- float explosionForce: The magnitude of the force to be applied (the larger the value, the more force will be applied)
- Vector3 explosionPosition: The center (origin) point of where the explosion is to take place (the further a GameObject is from this position, the less force it will receive)
- float explosionRadius: The furthest point beyond which no force will be applied by the simulated explosion
This method will apply a force to Rigidbody2D based on the direction...