Hi I asked chat GPT to create a action to get first active child of a game object. Is this correct?
using UnityEngine;
using HutongGames.PlayMaker;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Finds the first active child of a GameObject.")]
public class GetActiveChild : FsmStateAction
{
[RequiredField]
[Tooltip("The GameObject to search.")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
[Tooltip("Store the first active child in a GameObject variable.")]
public FsmGameObject storeResult;
public override void Reset()
{
gameObject = null;
storeResult = null;
}
public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
Finish();
return;
}
foreach (Transform child in go.transform)
{
if (child.gameObject.activeInHierarchy)
{
storeResult.Value = child.gameObject;
break;
}
}
Finish();
}
}
}