Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: liero116 on June 27, 2013, 06:58:32 AM
-
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?
-
Hi,
Good Point, I have updated the post to fix this.
http://hutonggames.com/playmakerforum/index.php?topic=982.msg4060#msg4060
Bye,
Jean
-
Perfect! Thanks!