Skip to content

Instantly share code, notes, and snippets.

@willt
Created September 28, 2017 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willt/c9f2c2326e64c45895b357e2a6ce46b9 to your computer and use it in GitHub Desktop.
Save willt/c9f2c2326e64c45895b357e2a6ce46b9 to your computer and use it in GitHub Desktop.
Adds a collider mask to a Platform Effector 2D
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics2D)]
[Tooltip("Adds a collider mask to a Platform Effector 2D")]
public class AddPlatformEffector2DColliderMask : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(PlatformEffector2D))]
[Tooltip("The GameObject with the PlatformEffector2D attached")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Layer)]
[Tooltip("The collision layer to add")]
public int collisionLayer;
public override void Reset()
{
gameObject = null;
collisionLayer = 0;
}
public override void OnUpdate()
{
DoAddMask();
Finish();
}
void DoAddMask()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
PlatformEffector2D pe = go.GetComponent<PlatformEffector2D>();
if (pe != null)
{
pe.colliderMask |= (1 << collisionLayer);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment