Skip to content

Instantly share code, notes, and snippets.

@peroon
Created September 4, 2017 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peroon/b3b5513cccae607c71aba7cc25484433 to your computer and use it in GitHub Desktop.
Save peroon/b3b5513cccae607c71aba7cc25484433 to your computer and use it in GitHub Desktop.
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