Help needed for begginer. With scripting items.

Hello guys so i wanted you to tell me how do i make this script shorter or universal.

first script what happens on pickup

	laikyk =;
if (laikyk == "iltis") {

info.gameObject.SendMessage("ilkiekis", 1);
else if (laikyk == "oda") {

info.gameObject.SendMessage("odkiekis", 1);


second script which stores information.
function ilkiekis (iltkiek : int) {
tiltkiek = tiltkiek + iltkiek;


function odkiekis (odokiekis : int) {
todkiek = todkiek + odokiekis;


bassicly first script is attached to every item in the game it Works pretty well well ofc thats not entire script so i want it to be able to somehow check the name of an item and create variable with its name and each time it is called it adds 1 to it ? so i dont need to write endless else if script. My main task is to make this script fully functional with every item without creating additional script (just in case you dont know when game launches it creates seperate instance of script for each item it is attached to)

Even if your not sure any help is great.


tried using arrays no luck i mean that might help to easier give meanings but i still need to write else if scripts

Hi. Your variable names are in… Latvian? Lithuanian? Polish?
It certainly makes it harder for other people here to understand the point of your code.

I think I understand you want to have some kind of “accountant” object (named info) that keeps track of how many different items have been picked up or something.

I would do this:

public class ItemTracker
    Dictionary<string,int> itemCountDict = new Dictionary<string,int>();
    public static void RegisterItem(string itemName, int itemAmount)
            itemCountDict[itemName] += itemAmount;
            itemCountDict.Add(itemName, itemAmount);
        Debug.Log(itemName+": "+itemCountDict[itemName]);

Then, you would use it from somewhere else like this:

var itemName =;
ItemTracker.RegisterItem(itemName, 1);

A dictionary is a collection of elements where every element has a key and a value. When you add elements to the dictionary, you provide the key and the value. Then, to retrieve the element from the dictionary at a later point, you use the key as an index.
For this example, I have created a Dictionary< string, int >, that is a dictionary where keys are of type string (for the item names) and values are of type int (for the amounts of every item).

I would very much recommend you to find a comprehensive C# course online and read it from the beginning to the end. It will teach you many of these tools that will make your programming life much much easier.