this worked like a charm before? and i don’t see why it doesn’t anymore …
public void PickUp(Item item)
{
Item i = new Component() as Item;
BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
foreach (PropertyInfo f in item.GetType().GetProperties(flags))
{
Debug.Log(f.PropertyType.Name);
if(f.PropertyType == typeof(Transform))
break;
f.SetValue(i, f.GetValue(item, null), null);
}
Inventory.itemList.Add(i);
Destroy(item.gameObject);
}
error:
TargetException: Non-static method requires a target.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:236)
System.Reflection.MonoProperty.SetValue (System.Object obj, System.Object value, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] index, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoProperty.cs:348)
System.Reflection.PropertyInfo.SetValue (System.Object obj, System.Object value, System.Object[] index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/PropertyInfo.cs:102)
PlayerCharacter.PickUp (.Item item) (at Assets/Scripts/CharacterScripts/PlayerCharacter.cs:69)
PlayerCharacter.LateUpdate () (at Assets/Scripts/CharacterScripts/PlayerCharacter.cs:57)