- Home /
Problems with Inventory System
I am working on an inventory system, and for some reason this code only prints the first name of the object in the list.
if(gameObject.GetComponent<PlayerControl>().dead == true)
{
foreach(GameObject weapon in weapons)
{
print(weapon);
weapon.gameObject.GetComponent<GunScript>().beingHeld = false;
}
}
Can anyone explain this?
And how your GetComponent is supposed to work without parameter? Look here, you should specify the type of component.
uhh I don't know why it says that. It is specified in my script.
Fixed your formatting for you. UA sometimes gets code formatting wrong.
This code should work. I would suggest doing a Debug.Log of weapons.count. Is it possible that you only have one item in your list?
I did do a debug on the count, and it says that there is 2 in the list at the point when the character is dead. But again it only lists the name of 1 of the items in the list. Also thanks for fixing the formatting.
no, although on second thought Unity is forcing phantom key strokes that aren't happening. Really wish they would make it less buggy, along with GUI suddenly not showing up, and onTrigger enters not working either.
Answer by Anxo · Sep 25, 2014 at 01:27 AM
do the 2 items have the same name? check the "collapse" is not on in your console window.
Your answer

Follow this Question
Related Questions
C# Problem Creating List of Texture2Ds 0 Answers
Problem with dropping items from my inventory 0 Answers
A node in a childnode? 1 Answer
generic list, swapping equipment errors but not always? 1 Answer
Endless counters in foreach loop 1 Answer