There's a custom action posted on here that changes an object's layer and the children of the object as well. This has worked great so far, but I also need it to change the layer of the children of the children as well.
Here is the code:
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Sets the layer and the layer of its children too")]
public class SetLayerRecursive : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Layer)]
public int layer;
public bool children;
public override void Reset()
{
gameObject = null;
layer = 0;
children = false;
}
public void DOSetLayer()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
go.layer = layer;
if (children)
{
foreach (UnityEngine.Transform child in go.transform){
child.gameObject.layer = layer;
}
}
Finish();
}
public override void OnEnter()
{
DOSetLayer();
}
public override void OnUpdate()
{
return;
}
}
}
Can someone assist me with this?