Is there a variable that simply stores a word so i can check it later?

Is there a way to store a single word as a variable so i can access it later?

What i want to do:

Have variables for ‘hotbar1’, ‘hotbar2’, ‘hotbar3’ … etc (each representing the designated slot in the hotbar)

Have it so an external script (an inventory manager) modifies the values of each hotbar variable is (for example, hotbar1 will become ‘handgun’ if the player equips a handgun in slot 1)

Have it so that when buttons 1, 2, 3 (etc) are pressed, the item currently in ‘hotbar1’ becomes the ‘held item’, which is the item that will display and be active.

I haven’t really worked with variables before, so it is confusing me somewhat.
Currently the line ‘public string hotbar1 = knife;’ (and the one after it) does not work, because knife hasnt been declared.

Is there a way to just store the variable as a single word?

My bad example code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hotbarmanager : MonoBehaviour {

    public string helditem;
    public string hotbar1 = knife;
    public string hotbar2 = rifle;

    void Update () {
        if (Input.GetKeyUp(KeyCode.1))
            helditem = hotbar1;

        if (Input.GetKeyUp(KeyCode.2))
            helditem = hotbar2;

Thanks :stuck_out_tongue:


your not really passing it a string value in your example you would maybe want to do this:

public string hotbar1 = "knife";

Unsure if this would be the most efficient way of doing this setup however.