Iam trying to get Vr Hand models using xr integration toolkit. iam using a hand controller script where it get input from controllers using and using another script which is on hand models to animate them, but iam getting a null reference exception error.
This is connected to the controller.
[RequireComponent(typeof(ActionBasedController))]
public class HandController : MonoBehaviour
{
// Start is called before the first frame update
ActionBasedController controller;
public Hand hand;
void Start()
{
controller = GetComponent<ActionBasedController>();
}
// Update is called once per frame
void Update()
{
hand.SetGrip(controller.selectAction.action.ReadValue<float>());
hand.SetTrigger(controller.selectAction.action.ReadValue<float>());
}
}
this is the hand script to animate
public class Hand : MonoBehaviour
{
Animator animator;
private float gripTarget;
private float triggerTarget;
private float gripCurrent;
private float triggerCurrent;
public float speed;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
UpdateHandAnimation();
}
internal void SetGrip(float v)
{
gripTarget = v;
}
internal void SetTrigger(float v)
{
triggerTarget = v;
}
void UpdateHandAnimation()
{
if (gripCurrent != gripTarget)
{
gripCurrent = Mathf.MoveTowards(gripCurrent, gripTarget, Time.deltaTime * speed);
animator.SetFloat("Grip", gripCurrent);
}
else
{
animator.SetFloat("Grip", 0);
}
if (triggerCurrent != triggerTarget)
{
triggerCurrent = Mathf.MoveTowards(triggerCurrent, triggerTarget, Time.deltaTime * speed);
animator.SetFloat("Trigger", triggerCurrent);
}
else
{
animator.SetFloat("Trigger", 0);
}
}
}