playMaker

Author Topic: 2D Toolkit TextMesh  (Read 2099 times)

ByronNilsson

  • Playmaker Newbie
  • *
  • Posts: 18
    • View Profile
2D Toolkit TextMesh
« on: September 22, 2011, 10:57:03 AM »
Just needed to use 2D toolkit for Score routine using textmesh, love 2d toolkit and PM, so be doing more efficient routines as needed :) Byron.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
   [ActionCategory("2D Toolkit")]
   [Tooltip("Changes Text on a tk2dTextMesh")]
   public class ChangeText : FsmStateAction {
      [RequiredField]
      public FsmOwnerDefault gameObject;
      [RequiredField]
      [UIHint(UIHint.Variable)]
      public FsmString newString;
      public bool everyFrame;
      
      private GameObject go;
      private tk2dTextMesh textMesh;
      
      public override void Reset() {
         gameObject = null;
         newString = null;
      }
      
      public override void OnEnter() {
         go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;
         textMesh = go.GetComponent<tk2dTextMesh>();
         textMesh.text = newString.ToString();
         textMesh.Commit();   
         if (!everyFrame)
         Finish();
      }
      
      
      public override void OnUpdate()
      {
         go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;
         textMesh = go.GetComponent<tk2dTextMesh>();
         textMesh.text = newString.ToString();
         textMesh.Commit();
      }

      
      
      
   }
}