Quantcast
Channel: Latest Questions by betaFlux
Viewing all articles
Browse latest Browse all 30

How to properly use blendshapes via script? (c#)

$
0
0
Hello, I need advice on how to script blendshape animations. What I try to do is, making a 25000 polygon female model blink with her eyes, in random intervals. The blendshapes are all showing up correctly on the mesh. I put the following script on it, but when I start the game view, the eyes are closing in big steps with no transition until they are almost completely shut and then unity crashes with the "unity editor stopped working"-message. I use this script, will try to comment my idea: using UnityEngine; using System.Collections; public class BlinkControl : MonoBehaviour { SkinnedMeshRenderer skinnedMeshRenderer; float blink = 0.0f; float blendSpeed = 1.0f; bool eyesClosed = false; void Awake() { skinnedMeshRenderer = GetComponent(); } void Start() { StartCoroutine(Blink()); } private IEnumerator Blink() { if(!eyesClosed && blink < 100.0f) //as long as the weight < 100 and eyes are open... { blendSpeed = 20.0f; skinnedMeshRenderer.SetBlendShapeWeight(46, blink); blink += blendSpeed; //...increase weight } else eyesClosed = true; if(eyesClosed) //if eyes are closed... { blendSpeed = 10.0f; skinnedMeshRenderer.SetBlendShapeWeight(46, blink); blink -= blendSpeed; //...decrease weight } else { eyesClosed = false; //set eyesClosed to false to restart the cycle... yield return new WaitForSeconds(Random.Range(1.0f,8.0f)); //...as soon as 1-8 seconds have passed } StartCoroutine("Blink"); //restart coroutine } } I don't know what the problem is. Any idea?

Viewing all articles
Browse latest Browse all 30

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>