|
| LayerMask | TargetLayerMask = LayerManager.PlayerLayerMask |
| | the layermask this magnetic enabler looks at to enable magnetic elements
|
| List< int > | MagneticTypeIDs |
| | a list of the magnetic type ID this enabler targets
|
| bool | OverrideFollowPositionSpeed = false |
| | if this is true, the follow position speed will be overridden with the one specified here
|
| float | FollowPositionSpeed = 5f |
| | the value with which to override the speed
|
| bool | OverrideFollowAcceleration = false |
| | if this is true, the acceleration will be overridden with the one specified here
|
| float | FollowAcceleration = 0.75f |
| | the value with which to override the acceleration
|
|
| virtual void | Awake () |
| | On Awake we initialize our magnetic enabler.
|
| virtual void | Initialization () |
| | Grabs the collider2D and ensures it's set as trigger.
|
| virtual void | OnTriggerEnter2D (Collider2D colliding) |
| | When something enters our trigger 2D, if it's a proper target, we start following it.
|
| virtual void | OnTriggerEnter (Collider colliding) |
| | When something enters our trigger, if it's a proper target, we start following it.
|
| virtual void | OnTriggerEnterInternal (GameObject colliding) |
| | If we trigger with a Magnetic, and the ID matches, we enable it.
|
This object will enable Magnetic objects in your scene when they enter its associated collider2D (make sure you add one). While magnetic objects can work on their own, and handle their own range detection, you can also use a different architecture, where an enabler makes them move. A typical use case would be to add it to a character, nested under its top level :
MyCharacter (top level, with a Character, controller, abilities, etc)
- MyMagneticEnabler (with this class and a CircleCollider2D for example)
Then, in your scene you'd have Magnetic objects, with StartMagnetOnEnter disabled. Your magnetic enabler would make them follow this specific target on enter. From the enabler you can also have it override the follow speed and acceleration.