Created
January 20, 2019 05:02
-
-
Save TomoG29/73f582135512e54c897d838365976ea7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
public class ShapeKeyTest : MonoBehaviour { | |
[SerializeField] | |
private GameObject TestObject; | |
[SerializeField] | |
private Slider key1Slider; | |
[SerializeField] | |
private Slider key2Slider; | |
[SerializeField] | |
private int key1Val; | |
[SerializeField] | |
private int key2Val; | |
[SerializeField] | |
private int preKey1Val; | |
[SerializeField] | |
private int preKey2Val; | |
// Use this for initialization | |
void Start () { | |
LoadObject(); | |
key1Val = 0; | |
preKey1Val = 0; | |
key2Val = 0; | |
preKey2Val = 0; | |
} | |
// Update is called once per frame | |
void Update () { | |
ChangeObject(); | |
} | |
private void LoadObject() | |
{ | |
TestObject = GameObject.Find("Sample"); | |
key1Slider = GameObject.Find("Key1Slider").GetComponent<Slider>(); | |
key2Slider = GameObject.Find("Key2Slider").GetComponent<Slider>(); | |
} | |
public void SetKey1Val() | |
{ | |
key1Val = (int)key1Slider.value; | |
} | |
public void SetKey2Val() | |
{ | |
key2Val = (int)key2Slider.value; | |
} | |
private void ChangeObject() | |
{ | |
if(key1Val != preKey1Val) | |
{ | |
preKey1Val = key1Val; | |
TestObject.GetComponent<SkinnedMeshRenderer>().SetBlendShapeWeight(0, key1Val); | |
} | |
if (key2Val != preKey2Val) | |
{ | |
preKey2Val = key2Val; | |
TestObject.GetComponent<SkinnedMeshRenderer>().SetBlendShapeWeight(1, key2Val); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment