Blendshape sliders

Hi, I’ve been having some trouble with my script using blendshapes. I have 2 sliders here; The first slider has a range of -100 to 100, and blends to 2 blendshapes. The second slider has a range of 0 to 100, and blends to a specific blendshape based on the current blendshape.
This script works pretty well for me, except that I would like to add one more blendshape when the first slider approaches 0 and the second slider approaches 100.
Additionally, when the second slider is greater than 0, and I move around the first slider, the blendshapes become weird.
I’ve been trying to figure this out by myself for a while, but I’m still very new to code, so any help would be appreciated :slight_smile:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class BlendShapeController : MonoBehaviour
{
    public float sliderValue1 = 0f;
    public float sliderValue2 = 0f;

    void Update()
    {
        GameObject[] objects = GameObject.FindGameObjectsWithTag("tag");

        foreach (var obj in objects)
        {
            var skinMesh = obj.GetComponent<SkinnedMeshRenderer>();

            if (sliderValue1 >= 0)
            {
                skinMesh.SetBlendShapeWeight(6, sliderValue1-sliderValue2);
                skinMesh.SetBlendShapeWeight(8, sliderValue2);
            }
        
            if (sliderValue1 <= 0)
            {
                skinMesh.SetBlendShapeWeight(12, -sliderValue1-sliderValue2);
                skinMesh.SetBlendShapeWeight(14, sliderValue2);
            }
        }
    }

    public void Slider1(float Slider1)
    {
        sliderValue1 = Slider1;
    }

    public void Slider2(float Slider2)
    {
        sliderValue2 = Slider2;
    }
}

I’ve finally found the solution to this, so I’ll post it here in case anyone has a similar issue :^)

public class BlendShapeController : MonoBehaviour
{
    public float sliderValue1 = 0f;
    public float sliderValue2 = 0f;

    void Update()
    {
        GameObject[] objects = GameObject.FindGameObjectsWithTag("tag");

        foreach (var obj in objects)
        {
            var skinMesh = obj.GetComponent<SkinnedMeshRenderer>();

            skinMesh.SetBlendShapeWeight(2, Mathf.Clamp(sliderValue2-Mathf.Abs(sliderValue1), 0, 100));

            if (sliderValue1 >= 0)
            {
                skinMesh.SetBlendShapeWeight(6, Mathf.Clamp(sliderValue1-sliderValue2, 0, 100));

                skinMesh.SetBlendShapeWeight(8, Mathf.Clamp((sliderValue2*sliderValue1)/100, 0, 100));
            }

            if (sliderValue1 <= 0)
            {
                skinMesh.SetBlendShapeWeight(12, Mathf.Clamp(Mathf.Abs(sliderValue1)-sliderValue2, 0, 100));

                skinMesh.SetBlendShapeWeight(14, Mathf.Clamp((sliderValue2*Mathf.Abs(sliderValue1))/100, 0, 100));
            }
        }
    }

    public void Slider1(float slider1)
    {
        sliderValue1 = slider1;
    }

    public void Slider2(float slider2)
    {
        sliderValue2 = slider2;
    }
}