SHARE
TWEET

Unity - Animation Blend Shapes

hussein87gabriel Jan 31st, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Animation Blend Shapes
  2.  
  3. //Using C#
  4.  
  5. using UnityEngine;
  6. using System.Collections;
  7.  
  8. public class BlendShapeExample : MonoBehaviour
  9. {
  10.  
  11.        int blendShapeCount;
  12.        SkinnedMeshRenderer skinnedMeshRenderer;
  13.        Mesh skinnedMesh;
  14.        float blendOne = 0f;
  15.        float blendTwo = 0f;
  16.        float blendSpeed = 1f;
  17.        bool blendOneFinished = false;
  18.  
  19.        void Awake ()
  20.        {
  21.           skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer> ();
  22.           skinnedMesh = GetComponent<SkinnedMeshRenderer> ().sharedMesh;
  23.        }
  24.  
  25.        void Start ()
  26.        {
  27.           blendShapeCount = skinnedMesh.blendShapeCount;
  28.        }
  29.  
  30.        void Update ()
  31.        {
  32.           if (blendShapeCount > 2) {
  33.  
  34.                  if (blendOne < 100f) {
  35.                     skinnedMeshRenderer.SetBlendShapeWeight (0, blendOne);
  36.                     blendOne += blendSpeed;
  37.                  } else {
  38.                     blendOneFinished = true;
  39.                  }
  40.  
  41.                  if (blendOneFinished == true && blendTwo < 100f) {
  42.                     skinnedMeshRenderer.SetBlendShapeWeight (1, blendTwo);
  43.                     blendTwo += blendSpeed;
  44.                  }
  45.  
  46.           }
  47.        }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top