Search Unity

Equiping an item...

Discussion in 'Scripting' started by Twidusk Studios, Aug 16, 2010.

  1. Twidusk Studios

    Twidusk Studios

    Joined:
    Aug 13, 2010
    Posts:
    42
    Code (csharp):
    1. var inventory : Texture2D;
    2. var item : Transform;
    3. var weaponbone : Transform;
    4. function OnGUI () {
    5. GUI.BeginGroup (Rect (1150, 550, 300, 50));
    6.     GUI.Box (Rect (0,0,200,50), "");
    7.     if (GUI.Button (Rect (0,0,200,50), "Click")){
    8.         //instantiating equiped item
    9.         var weap = Instantiate(item,
    10.                             GameObject.Find("WeaponEquip").transform.position,
    11.                             Quaternion.identity);
    12.                            
    13.     }
    14.     GUI.EndGroup ();
    15. }
    im trying to instantiate the weapon prefab at the same coordinates, which is working, but it is always facing the z axis. i want it to instantiate the weapon looking at the same axis and rotation as the weaponbone var. how am i to do this? or maybe i can do
    Code (csharp):
    1. weaponbone = item;
    why is this not working?
     
  2. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    You are setting it's rotation to Quaternion.identity. If you want it to be facing the same way, you need to put in
    Code (csharp):
    1. weaponbone.rotation
    Instead.
     
  3. Twidusk Studios

    Twidusk Studios

    Joined:
    Aug 13, 2010
    Posts:
    42
    wow, thanks! i didnt even think of that :) ill try it now!