Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

C# How can I return the "left_hand" as a game object?

Discussion in 'Scripting' started by From-Soy-Sauce, Sep 3, 2014.

  1. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Hello, the system I have set up right now is that the Player object, on start:
    Code (CSharp):
    1. MyMod=Instantiate("SAKUYA_MODEL",transform.position,transform.rotation) as GameObject;
    And in the Update:
    Code (CSharp):
    1. MyMod.transform.position = new Vector3 (transform.position.x, transform.position.y, transform.position.z);
    And other things like the animation are told to MyMod through the player object.

    MyMod has an animation in it, and one of the bones it uses is named "left hand" I noticed that when running the game that in the heirchy under the SAKUYA_MODEL object that gets instantiated, that I can find "left_hand" as an object.

    How can I return the "left_hand" bone as a game object variable that can be used for the Player object?

    I imagine it would be something like:

    MyMyd.Bone.left_hand or something like that, but I can't seem to find a way to do it.
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Drag the hand to a public variable on your script?
     
  3. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Yes I understand that that is one way to do it, but how would I do that only using C# programming? I'd like to avoid using the inspector as much as possible.
     
  4. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
  5. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    I have heard of this command before, and I've been trying to figure out how to use it for 2 days, but no matter what I try I cannot seem to be able to figure out how to get it to work in my exact (described above) situation.
     
  6. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Looking at this:
    I would guess:
    Code (csharp):
    1. GameObject leftHand = myMod.transform.Find ("Bone/left_hand").gameObject;
     
  7. From-Soy-Sauce

    From-Soy-Sauce

    Joined:
    Jan 7, 2014
    Posts:
    162
    Thanks! It works like a charm!