Skip to content

Instantly share code, notes, and snippets.

@willt
Created September 28, 2017 02:59
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/80389584e207398f1209d9fcb699ef8f to your computer and use it in GitHub Desktop.
Save willt/80389584e207398f1209d9fcb699ef8f to your computer and use it in GitHub Desktop.
Removes a collider mask from a Platform Effector 2d
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics2D)]
[Tooltip("Removes a collider mask from a Platform Effector 2d")]
public class RemovePlatformEffector2DColliderMask : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(PlatformEffector2D))]
[Tooltip("The GameObject with the PlatformEffector2D attached")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Layer)]
[Tooltip("The collision layer to remove")]
public int collisionLayer;
public override void Reset()
{
gameObject = null;
collisionLayer = 0;
}
public override void OnUpdate()
{
DoRemoveMask();
Finish();
}
void DoRemoveMask()
{
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