- Home /
how to use vectors to control an outcome
I need to find a game object and look through the object for the children finding their position subtracting vector A from vector B to find the points between each.
If vector A is above vector B then do this...
The points the vectors are attached to will constantly be moving as object is controlled using gestures
The code below is what I have written to find the children of the game object.
I would need to use the vectors to figure out the position of the children. To extend my example I would need: if the left hand is above left elbow then it should do this..
public class kinectman : MonoBehaviour{ public GameObject man;
GameObject lefthand; GameObject leftelbow; GameObject righthand; GameObject rightelbow;
void breakdown() {
lefthand = GameObject.Find("13_Hand_Left");
leftelbow = GameObject.Find("11_Elbow_Left");
righthand = GameObject.Find("23_Hand_Right");
rightelbow = GameObject.Find ("21_Elbow_Right");
}
}
Running 4 Find methods in a row is a horrible use of resources. $$anonymous$$ight I suggest finding objects in children? An example might be.
GameObject[] parts = GetComponentsInChildren<GameObject>();
for (int i = 0; i < parts.Length; i++)
{
if (parts[i].name == "13_Hand_Left")
{
lefthand = GameObject.Find("13_Hand_Left");
}
else if (parts[i].name == "13_Hand_Right")
{
righthand = GameObject.Find("13_Hand_Left");
}
}
if (lefthand.transform.position.y > leftelbow.transform.position.y)
{
//do stuff
}
Why would you want to call GameObject.Find after you have already found the GameObject as parts[i]?
Your answer
Follow this Question
Related Questions
Keyframes of animated Child gameobject not shown by parent gameobjects animator issue ? 0 Answers
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
how to reference child in a prefab within a prefab 0 Answers
How to change game object position smoothly not snapping to the position 1 Answer
Limit space for a child object 2 Answers