Skip to content

Instantly share code, notes, and snippets.

@TwoTenPvP
Created June 14, 2017 06:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TwoTenPvP/29684118fb37d1de946aee03307d80c1 to your computer and use it in GitHub Desktop.
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
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