-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClothMovement.cs
More file actions
49 lines (45 loc) · 1.15 KB
/
Copy pathClothMovement.cs
File metadata and controls
49 lines (45 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using System.Collections;
public class ClothMovement : MonoBehaviour {
public int start = 0;
public int index = 0;
public int increase = 1;
private float val = 50f;
private int shapeCount;
private SkinnedMeshRenderer skinnedMeshRend;
private Mesh clothMesh;
void Start ()
{
skinnedMeshRend = GetComponent<SkinnedMeshRenderer>();
clothMesh = GetComponent<SkinnedMeshRenderer>().sharedMesh;
shapeCount = clothMesh.blendShapeCount;
skinnedMeshRend.updateWhenOffscreen = false;
}
void Update () // Traversing through each shape key/frame
{
skinnedMeshRend.SetBlendShapeWeight(index, 0.0f); // Turn off previous shape key
if(increase == 1) // Traversing down array
{
if(index < (shapeCount - 1)){
index++;
}
else // access last shape key
{ // then reverse traverse
increase = 0;
index--;
}
}
else // Traversing back up array
{
if(index > start){
index--;
}
else // access first shape key
{ // then traverse back down
increase = 1;
index++;
}
}
skinnedMeshRend.SetBlendShapeWeight(index, val); // Turn on current shape key
}
}