Question by
xamidium · Aug 16, 2021 at 04:24 AM ·
animatorscripting beginnerscriptingbasics
Animator Parameter Scripting,
I'm trying to use the the float value of a knob on a controller to control the float value of the motion time parameter of my animation.
Basically when the knob is at 0, I want the animation to be at it's first frame, and when the knob is at 1, I want the animation to be at it's last frame. I have the value of the knob in my script, but I am struggling to connect it to the motion time parameter.
Here is my script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GreenKnobScrubber : MonoBehaviour
{
public PerTrack controls;
public float GreenKnobWValue;
Animator m_Animator;
void Awake()
{
controls = new PerTrack();
controls.TrackControl1.GreenKnobW.performed += x => GreenKnobWValue = x.ReadValue<float>();
}
// Use this for initialization
void Start()
{
//Get the animator, which you attach to the GameObject you are intending to animate.
m_Animator = gameObject.GetComponent<Animator>();
m_Animator.speed = 0;
}
public void OnEnable()
{
controls.Enable();
}
void OnDisable()
{
controls.Disable();
// Update is called once per frame
void Update()
{
m_Animator.SetFloat("Position", GreenKnobWValue);
}
}
}
,
Comment
Your answer
