using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Animations.Rigging;

public class ActivateConstraintWeightOnEnter : MonoBehaviour
{
    [SerializeField] TwoBoneIKConstraint[] m_constraintTwoBone;
    [SerializeField] MultiAimConstraint[] m_constraintMultiAim;
    [SerializeField] AimConstraint[] m_constraintAim;
    [SerializeField] float m_transitionSpeed = 10.0f;

    float m_targetWeight = 0;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        foreach(TwoBoneIKConstraint c in m_constraintTwoBone) c.weight = Mathf.Lerp(c.weight, m_targetWeight, Time.deltaTime * m_transitionSpeed);
        foreach(MultiAimConstraint c in m_constraintMultiAim) c.weight = Mathf.Lerp(c.weight, m_targetWeight, Time.deltaTime * m_transitionSpeed);
        foreach(AimConstraint c in m_constraintAim) c.weight = Mathf.Lerp(c.weight, m_targetWeight, Time.deltaTime * m_transitionSpeed);
    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player") m_targetWeight = 1;
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "Player") m_targetWeight = 0;
    }
}
