playMaker

Author Topic: [SOLVED]Change layer recursively  (Read 9109 times)

liero116

  • Playmaker Newbie
  • *
  • Posts: 21
[SOLVED]Change layer recursively
« 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:

Code: [Select]
// (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?
« Last Edit: June 28, 2013, 02:39:25 PM by liero116 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Change layer recursively
« Reply #1 on: June 27, 2013, 02:47:57 PM »
Hi,

 Good Point, I have updated the post to fix this.

http://hutonggames.com/playmakerforum/index.php?topic=982.msg4060#msg4060

Bye,

 Jean

liero116

  • Playmaker Newbie
  • *
  • Posts: 21
Re: Change layer recursively
« Reply #2 on: June 28, 2013, 02:39:07 PM »
Perfect!  Thanks!