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
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;
}
}