Best way to organize 3 specific script interaction

I have 3 scripts that I want to interact with each other:

  • Customer script - contains gender, age, budget, etc. Different for every customer (randomized) attached to customer
  • AI Script - contains decision making functions. Same for every customer. attached to customer
  • Catalog script - contains all items and all stats about the item. attached to gameMaster

How it interacts

  1. Customer accesses AI script to look
    at item
  2. AI script gains information from customer script for demographic info
  3. AI script accesses Catalog script for stats about item for decision
    making
  4. Returns a bool that decides whether to buy or not
  5. If buy, subtract money from customer budget and move on
  6. If not buy, walk away and look for another item

Is the the most efficient way to do this? I have about 200 items in the catalog script. What is the best way to organize these 3 scripts?

This seems to be a problem with OOP in general, and not Unity-specific.

You can use the ‘GetComponent()’ and ‘FindObjectOfType()’ to get references to the components from the other components, and have public methods on those components to pass information around among them.

That method seems to be efficient enough. Although I don’t know what type of information your ‘items’ in your catalog script contains, searching for something through 200 of something will generally not be that inefficient of an operation.