playMaker

Author Topic: Sets the value of a Child TextMesh Variable  (Read 1077 times)

unclebob

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Sets the value of a Child TextMesh Variable
« on: May 27, 2015, 08:26:07 AM »
Hi all

This works but is there a more efficient way?

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using UnityEngine;
using UnityEngine.UI;
using System;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.String)]
[Tooltip("Sets the value of a TextMesh Variable.")]
public class SetTextMeshValue : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmOwnerDefault gameObject;
public FsmString StringtoChange;
public bool everyFrame;

public override void Reset()
{
gameObject = null;
StringtoChange = null;
everyFrame = false;
}

public override void OnEnter()
{
DoSetStringValue();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoSetStringValue();
}

void DoSetStringValue()
{
if (StringtoChange == null) return;
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
go.GetComponent<TextMesh>().text = StringtoChange.Value;
}

}
}

Cheers

UB