- Home /
Comparing similarly-named variables.
I've got one script which references the scripts within two objects.
The script is supposed to take each bone in the first object, change it based on the variable in the script, and then change it again based on a variable of the same name in another script. It then parents the bone of the first object to the same bone of the second object.
This script has been a bit butchered, but it might help visualize a bit.
How can I reference the variables by their names? Or perhaps there is another way to do this?
void tailor(GameObject Equip, GameObject Target) { Equipment equipmentData = Equip.GetComponent<Equipment>(); Character characterData = Target.GetComponent<Character>();
foreach (Transform bone in Equip) {
string boneName = bone.name;
bone.localScale = (bone.localScale / equipmentData.boneName.localScale);
bone.localScale = (bone.localScale * characterData.boneName.localScale);
bone.parent = Target.bone;
bone.localPosition = Vector3.zero;
bone.localRotation = Target.bone.rotation;
}
}
Answer by Case23 · Jun 23, 2010 at 07:55 AM
If i understand it right, you can simple use a function with if clause like.
public int getSpecificBoneLocalScale (string boneName)
{
If(boneName.Equals(specificBoneName))
{
return specificBone.localScale;
}
}
Ah, so that will refer to a bone of the same name? Is there a way to do it with a variable?
Im not sooo deep into unity till now, and i dont know if bone is a build in thing. But it does not directly refer to the bone with the same name. You check if the string name of the bone equals the string you send. After this you can choose which bone should return. Problem here is, you have to mak an if() for every sepcific Bone.
Your answer
Follow this Question
Related Questions
Converting String to Variable Name 3 Answers
String as Variable name 0 Answers
Left-hand side of an assignment must be a variable, property or an indexer 1 Answer
How to Get a Char from his name ? 1 Answer