Question by
Vandal16 · Jul 14, 2020 at 04:42 PM ·
scripting problemscript errorhow-to
How can I access a variable that's in a StateMachineBehaviour script
Hi, can I access a variable like "speed" from a StateMachineBehaviour script through another script that is a MonoBehaviour script? I tried ScriptName sn; and then GetComponent(); and for access the speed variable i did sn.speed = 1f; but that put me only an error that i can't reference the StateMachineBehaviour script as GameObject. Then how can I access it? Or there is no way to access it ? This is my script
using UnityEngine;
public class ScriptName : StateMachineBehaviour
{
public float speed;
}
Comment
Best Answer
Answer by navka200 · Jul 15, 2020 at 09:32 AM
You can use Animator.GetBehaviour. Like this:
animator.GetBehaviour<ScriptName >().speed = ...