So as said in the title I need help with making an inventory system using unityscript. I have tried searching the forum and Google since Wednesday but I didn’t find any good tutorials etc. to suit my needs. Inventory system is going to be used in first person adventure game, but I guess it will be easy to use in other type of games too.
How I thought the system would work: Four scripts: inventory, pick up, equip item and item script (which is attached to the gameobject). So far I have started the pick up script. Script is attached to the main camera, when you look at gameobjective which has tag “item” you will see message “press E to pick up” (Later on adding something like item name and stats would be awesome). When you press E, the gameobject will be destroyed. Gameobjects that you can pick up have item script which currently only has two variables: name and id.
Pick up script: after the item gets destroyed (deleted from scene) would it be possible to check the id (or name of the prefab etc.) and add it to inventory. I had the destroy part but I decided to remove it because I messed it up somehow and I couldn’t get it working.
var rayLenght : int = 10;
var ShowText : boolean = false;
function Update ()
{
var hit: RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, hit, rayLenght))
{
if(hit.collider.gameObject.tag == "Item")
ShowText = true;
}
else {
ShowText = false;
}
}
function OnGUI() {
if (ShowText) {
GUILayout.Label("Press E to pick up");
}
}
Inventory: I’m not sure how arrays/arraylists work but how I thought it would go: there is some place (array?) which consists of item id’s (that are in the item script, on item prefabs). When you press lets say tab, it opens ui (haven’t thought of that because of the new ui system I have no knowledge about) it shows the items you have (script checks the id and displays right icon) and you could equip for example a sword which would show in your hand (Not necessary atm, I would like to have other things working first). Also you should be able to remove item from inventory, check item id, spawn it in front of player.
So if anyone could guide me what should I do and how, it would be more than appreciated! Any tutorials, videos and example scripts would be awesome.
Obviously I am a beginner and some people may find these threads annoying, but I’m trying to learn scripting. Also I apologize for any grammatical mistakes and typos.