Created
June 14, 2017 06:34
-
-
Save TwoTenPvP/29684118fb37d1de946aee03307d80c1 to your computer and use it in GitHub Desktop.
A script for the Unity3D game engine that allows clothing and other things to animate along with the main character
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
public class Equipmentizer : MonoBehaviour | |
{ | |
public SkinnedMeshRenderer TargetMeshRenderer; | |
void Start() | |
{ | |
Dictionary<string, Transform> boneMap = new Dictionary<string, Transform>(); | |
foreach (Transform bone in TargetMeshRenderer.bones) | |
boneMap[bone.gameObject.name] = bone; | |
SkinnedMeshRenderer myRenderer = gameObject.GetComponent<SkinnedMeshRenderer>(); | |
Transform[] newBones = new Transform[myRenderer.bones.Length]; | |
for (int i = 0; i < myRenderer.bones.Length; ++i) | |
{ | |
GameObject bone = myRenderer.bones[i].gameObject; | |
if (!boneMap.TryGetValue(bone.name, out newBones[i])) | |
{ | |
Debug.Log("Unable to map bone \"" + bone.name + "\" to target skeleton."); | |
break; | |
} | |
} | |
myRenderer.bones = newBones; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment