I did research to find a answer but none helped. My model is exported from MakeHuman and when I try to attack to a hand model I cannot seem to find it as it only gives me a mesh when I look at hands. I also tried scriptting it in but I keep getting errors.
Script(c#);
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wrench : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
foreach (Transform joint in hierarchy)
{
if (joint.name == "RHandAttachPoint")
{
Debug.Log("found the attach point anyways");
//add the item
this.transform.position = joint.transform.position;
this.transform.rotation = joint.transform.rotation;
this.transform.parent = joint;
return;
}
}
}
}
Error I get:
error CS0103: The name `hierarchy' does not exist in the current context\
I found no awnsers for that either.
Please helpâŚ
[SOLVED!]
In this I have used the script to figure out if the problem is scripting so I am not 100% sure if it is the script that fixed it but I also put the Model into the Hand_r which I had too look through under:
GameEngine > Root > Pelvis > Spine_01 > Spine_02 > Spine_03 > Calvical_r > Upperarm_r > Lowerarm_r > Hand_r (Drop model into this by dropping it onto the word Hand_r)
âhierachyâ means nothing in the scope you are working, you could type âzxyoiuqweâ and get same compilation error.
You are trying to get the hand joint from your human model, and you are trying to do that from the script attached to your wrench, thatâs fine but the wrench script has no concept of the human model.
If you want to bind the wrench to the human from within the wrench script then you need to first get a reference to the human model in the scene.
One way to do that is to add a scene tag to your human model prefab or scene instance of it.
In this example we will tag it âPLAYERâ.
In this example you will need to type in your full joint heirachy to replace mine.
Also you should not do that in update, update happens every frame, you only need do it in Start or Awake of the wrench, or using some public function from elsewhere if you want the wrench to exist in the scene and then be able to pick it up or drop it .
with the full heirachy path to your models hand transform.
to find the full heirachy, put your human model in the scene, then look in scene explorer panel, expand the human heirachy to find all the skeleton joints and then make a note of the full path to the hand. This path may be quite long and youâve got to be careful of typos.
Well the fact that you got that far means you are succesfully grabbing your tagged human model, so you know how to do that from anywhere in script now.
You could also use the method in your OP to find the joint, it just takes a few more microseconds.
Code for that is:
// GET HUMAN MODEL
GameObject oHuman = GameObject.FindGameObjectWithTag("PLAYER");
if(!oPlayer)
{
Debug.LogWarning("CANT GET: PLAYER");
return;
}
// LOOK FOR BIND JOINT
string sJoint = "RHandAttachPoint";
foreach (Transform joint in oHuman.transform)
{
if (joint.name == sJoint)
{
Debug.Log("found the attach point anyways");
//add the item
this.transform.SetPositionAndRotation(joint.transform.position, joint.transform.rotation);
this.transform.parent = joint;
// GOOD BIND
return;
}
}
// BAD BIND
Debug.LogWarning("CANT FIND JOINT " + sJoint);