Author Topic: Adding items into inventory through coding  (Read 2491 times)

Aeneas

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Adding items into inventory through coding
« on: July 15, 2014, 10:27:19 AM »
Hey y'all.
I recently bought NGUI, and was wondering how you would go about adding an item into the inventory through coding.
Or shall I say, which script shows you how to start working on this type of implementation.

I've had a look at the EquipRandomItem.cs script, but that goes on about auto equipping an item, instead I want an item to go into the inventory.

The problem is, as the slots are added during run time, how would you then check the slots and then add something in yourself?
Any help is appreciated even if it's just a point in the right direction :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Adding items into inventory through coding
« Reply #1 on: July 15, 2014, 09:56:33 PM »
I always suggest creating a prefab out of what you want, then dynamically changing its content after instantiation. It's always much easier than setting up everything via code.

However... if you insist on making stuff via code, look at the UICreateWidgetWizard script. It has code in it that's able to create all kinds of basic NGUI widgets via code.