playMaker

Author Topic: Custom action for changing Animator Variable  (Read 2644 times)

Sly

  • Full Member
  • ***
  • Posts: 123
Custom action for changing Animator Variable
« on: January 14, 2014, 11:44:19 AM »
Hello guyz,

I'm trying to make a new action (for sure I will share it when is done) for changing Unity Animator variable. With this it can be possible to manage the animator with this.
I try my code but it's not working. There is my code:

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Animation)]
    [Tooltip("Change a variable in the Unity Animator")]

    public class AnimatorChangeVariable : FsmStateAction
    {
        [RequiredField]
        [Tooltip("The name of animator variable to change.")]
        public FsmString NameOfTheVariable;   
        private Animator anim;                    // Reference to the player's animator component.
        private string FinalVariable;

        public override void Reset()
        {
            NameOfTheVariable = "MyVariable";
        }
       
        public override void OnEnter()
        {
            FinalVariable = NameOfTheVariable.Value;
            anim.SetBool(FinalVariable, true);
        }

    }
}

I tried using a name directly with the anim.SetBool command and it's not even worked. (anim.SetBool(Walk, true);)
I didn't succeed to link the Animator Variable.
Can someone help me with my syntaxe please?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Custom action for changing Animator Variable
« Reply #1 on: January 14, 2014, 12:52:19 PM »
Why not just use SetAnimatorBool?
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Custom action for changing Animator Variable
« Reply #2 on: January 14, 2014, 12:59:40 PM »
I don't find this action in my action list. I don't know where to find it.
Is it normal?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Custom action for changing Animator Variable
« Reply #3 on: January 14, 2014, 01:00:47 PM »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Custom action for changing Animator Variable
« Reply #4 on: January 14, 2014, 02:37:30 PM »
Ah perfect! Thanks for you help guy, I'm gonna check that :)