- Home /
Equipting a Item/Weapon
I've made a Script that adds a very basic Inventory and GUI. I'm stuck on equipping the item. It will equip and parent to the bone the way it is supposed to but the object doesn't line itself up right with my character. Can someone help out with this? I'm sure its a somewhat simple solution I just can't seem to figure it out though.
import System.Collections.Generic;
var playerInventory : List.<ItemClass> = new List.<ItemClass>();
var scrollView : Vector2;
var equippedItem : ItemClass;
var equipped : boolean = false;
var playerHand : Transform;
function Update ()
{
if(equippedItem.itemType == ItemClass.ItemType.Weapon && equipped == false)
{
equipped = true;
}
else
{
equipped = false;
}
}
function OnGUI()
{
//Inventory
GUILayout.BeginArea(Rect(Screen.width - 300, 0, 300, 508));
scrollView = GUILayout.BeginScrollView(scrollView,GUILayout.Width(300), GUILayout.Height(508));
for(var x = 0; x < playerInventory.Count; x++)
{
GUILayout.BeginHorizontal();
//Equipping a Weapon.
if(GUILayout.Button(playerInventory[x].icon) && playerInventory[x].itemType == ItemClass.ItemType.Weapon)
{
equippedItem = playerInventory[x];
var weapon : Transform = Instantiate(playerInventory[x].itemPrefab,playerHand.position,Quaternion.identity);
playerInventory.RemoveAt(x);
weapon.parent = playerHand;
return;
}
GUILayout.Box(playerInventory[x].name);
GUILayout.EndHorizontal();
GUILayout.Box(playerInventory[x].description);
}
GUILayout.EndScrollView();
GUILayout.EndArea();
//Weapon Slot
if(GUI.Button(Rect(Screen.width/2 - 25, Screen.height - 50, 50, 50), equippedItem.icon) && equipped == true)
{
playerInventory.Add(equippedItem);
Destroy(GameObject.FindGameObjectWithTag("Weapon"));
equippedItem = new ItemClass();
}
}
Answer by Sulbon · Oct 10, 2013 at 06:49 AM
weapon.parent = playerHand;
weapon.localPosition = Vector3.zero;
weapon.localRotation = Identity
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Inventory armor wielding proplem,How to convert from derived to base 1 Answer
How to make an inventory for my text advenutre? 0 Answers
Decorator pattern for inventory item class 0 Answers
Inventory System: How to detect equal items on a list for increasing amount? 0 Answers