Created
September 4, 2017 06:38
-
-
Save peroon/b3b5513cccae607c71aba7cc25484433 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 UnityEngine; | |
using System.Collections; | |
using DG.Tweening; | |
// ランダムで目パチ | |
public class Mepachi : MonoBehaviour { | |
// 調整パラメータ | |
public int blendShapeIndex = 0; | |
public float interval = 3.0f; | |
public float noise = 1.0f; | |
public float minWeight = 0.0f; | |
public float maxWeight = 0.0f; | |
public float tweenTime = 0.5f; | |
private SkinnedMeshRenderer skinnedMeshRenderer; | |
private float weight; | |
void Start () { | |
// cache | |
skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer> (); | |
weight = minWeight; | |
StartCoroutine (ChangeWeight ()); | |
} | |
IEnumerator ChangeWeight(){ | |
while (true) { | |
float thisTimeTweenTime = tweenTime * Random.Range (0.5f, 1.0f); | |
DOTween.To (x => weight = x, minWeight, maxWeight, tweenTime).SetLoops (2, LoopType.Yoyo); | |
float waitTime = interval + Random.Range(-1.0f, 1.0f) * noise; | |
yield return new WaitForSeconds (waitTime); | |
} | |
} | |
void Update () { | |
// 毎フレーム反映 | |
this.skinnedMeshRenderer.SetBlendShapeWeight (blendShapeIndex, weight); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment