# Need help fixing a level system script

**URL:** https://discussions.unity.com/t/need-help-fixing-a-level-system-script/1558723
**Category:** C# & .NET
**Tags:** Scripting, 2022.3-lts, C-Sharp, Question
**Created:** [November 24, 2024, 12:18am UTC](https://discussions.unity.com/t/need-help-fixing-a-level-system-script/1558723 "2024-11-24T00:18:01Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [November 24, 2024, 12:20am UTC](https://discussions.unity.com/t/need-help-fixing-a-level-system-script/1558723/2 "2024-11-24T00:20:57Z")

</div>

> [@KenChiimken](#):
>
> Need help solving the issue

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

> **[Unity - Manual: Debug C# code in Unity](https://docs.unity3d.com/Manual/managed-code-debugging.html)**

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use `Debug.Log(...);` statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

Here’s some extra notes about inventories:

These things (inventory, shop systems, character customization, dialog tree systems, crafting, ability unlock systems, tech trees, etc) are fairly tricky hairy beasts, definitely deep in advanced coding territory.

The following applies to ALL types of code listed above, but for simplicity I will call it “inventory.”

Inventory code never lives “all by itself.” All inventory code is EXTREMELY tightly bound to prefabs and/or assets used to display and present and control the inventory. Problems and solutions must consider both code and assets as well as scene / prefab setup and connectivity.

If you contemplate late-delivery of content (product expansion packs, DLC, etc.), all of that has to be folded into the data source architecture from the beginning.

Inventories / shop systems / character selectors all contain elements of:

- a database of items that you may possibly possess / equip
- a database of the items that you actually possess / equip currently
- perhaps another database of your “storage” area at home base?
- persistence of this information to storage between game runs
- presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
- interaction with items in the inventory or on the character or in the home base storage area
- interaction with the world to get items in and out
- dependence on asset definition (images, etc.) for presentation  
 → what it looks like lying around in the world? In a chest? On a shelf?  
 → what it looks like in the inventory window itself?  
 → what it looks like when worn by the player? Does it affect vision (binoculars, etc.)  
 → what it looks like when used, destroyed, consumed?

Just the design choices of such a system can have a lot of complicating confounding issues, such as:

- can you have multiple items? Is there a limit?
- if there is an item limit, what is it? Total count? Weight? Size? Something else?
- are those items shown individually or do they stack?
- are coins / gems stacked but other stuff isn’t stacked?
- do items have detailed data shown (durability, rarity, damage, etc.)?
- can users combine items to make new items? How? Limits? Results? Messages of success/failure?
- can users substantially modify items with other things like spells, gems, sockets, etc.?
- does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
- etc.

Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

Breaking down a large problem such as inventory:

> [@Weapon Inventory and how to script weapons.](https://discussions.unity.com/t/weapon-inventory-and-how-to-script-weapons/826141/4):
>
> You’re welcome of course. One thing you could try to really get a “feel” for what happens in this case is make a simple script that is just one cell of your inventory. Put this into a script that you can access through an “inventory API” that does certain things to a cell. These functions might be: “Set the type of item” “Query the type and quantity of item in this cell” “Add 1 item to this cell.” “Add N number of items to this cell.” “Remove N item from this cell.” Then you can have pr…

If you want to see most of the steps involved, make a “micro inventory” in your game, something whereby the player can have (or not have) a single item, and display that item in the UI, and let the user select that item and do things with it (take, drop, use, wear, eat, sell, buy, etc.).

Everything you learn doing that “micro inventory” of one item will apply when you have any larger more complex inventory, and it will give you a feel for what you are dealing with.

Breaking down large problems in general:

> [@Options for implementing mining/digging in an asteroid belt game?](https://discussions.unity.com/t/options-for-implementing-mining-digging-in-an-asteroid-belt-game/908126/3):
>
> Whenever engineering seems too much to tackle, it’s always best to see if you can break the problem down. What you describe above is by no means simple, as just the different ways all of it could be implemented are complex: does the camera rotate with the player on the asteroid? Do the player’s controls rotate as they walk around the asteroid? Does the camera lock to the rotating asteroid? What does the camera do if the player digs down a ways? If the player digs a tunnel into the asteroid, d…

The moment you put an inventory system into place is also a fantastic time to consider your data lifetime and persistence. Create a load/save game and put the inventory data store into that load/save data area and begin loading/saving the game state every time you run / stop the game. Doing this early in the development cycle will make things much easier later on.

Various possible inventory data structures in Unity3D:

> [@Inventory/Item system](https://discussions.unity.com/t/inventory-item-system/921694):
>
> So i’ve been trying for a while now to figure out a good item system for my game. I thought I found a solution by using GameObjects as items, since it checked all of my requirements: The item needs to be visible when equipped (I just position the GameObject to the correct slot) The item needs to be an instance, that is, have unique values such as durability and other fields specific to certain items It needs to have a pickup with proper colliders. That is, the colliders should match the shape …

---

_[View the full topic](https://discussions.unity.com/t/need-help-fixing-a-level-system-script/1558723)._
