Hi there! I am a beginner in Unity and I am making a 3D game with a fixed camera where there are a bunch of NPC’s standing in the middle of a square. You get an item from a minigame and if you talk to those NPC’s, you can trade your item for theirs. I figured you will need the if and else if but I’m not entirely sure how to add the inventory system and then how to make it so they can trade their items. I was wondering if anyone can help me with this.
Well there is a inventory system provided by unity, but I think it’s connected to analythics and stuff and maybe you don’t need that:
https://docs.unity3d.com/Packages/com.unity.game.foundation@0.6/manual/index.html
But there are also free inventory systems available at store (as well as some you can buy, which will provide a nice ui and extra features)
Also there are tutorials on youtube and so on.
It depends on what you actually need - if you just need items that don’t stack, maybe just use lists and keep things simple?
Inventory is something that can be solved in so, so many ways.
describe it in plain english first otherwise you’ll be pulling your hair out trying to write code for something you havent properly thought through first.
Like: I have a chicken. Under what conditions can I trade it for a pig? What are the conditions that the NPC would say yes, I will trade pig for chicken, and what are the conditions he will say no.
Start with just like, three conditions. When you can describe those clearly in plain english, it wont be hard for pretty much any programmer to describe exactly how to translate that into code. To begin with all the logic can be verified just using debug logs (just printing some text to the screen.)
Don’t bother doing anything more than printing text until you have all the logic verified.
From there the specifics of your game will inform you how to make this simple system bigger - but that’s a problem for another day. Got to get the basics done first.
I wouldnt jump at a premade inventory system at this point because it wont make any sense to you. Hell is other peoples code, as they say. And if you don’t know much about reading code, it is deep fried hell. Tutorials might be a good idea. But just the basics of code like how to put items into an array and then filter through the array, and perform some checks using if/else and other methods will be the most important thing to get started with. You’ll learn more by doing some basic tutorials and then practicing tiny baby steps on your own, versus trying to get some premade system working by toggling checkboxes on and off and scratching your head.