Advertisement
hussein87gabriel

Unity - Animation Blend Shapes

Jan 31st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement