Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity c# struct

struct InventorySlot {
    //Variable declaration
    //Note: I'm explicitly declaring them as public, but they are public by default. You can use private if you choose.
    public bool IsFree;
    public string Name;
   
    //Constructor (not necessary, but helpful)
    public InventorySlot(bool isFree, string name) {
        this.IsFree = isFree;
        this.Name = name;
    }
}
//With this code, you can create a new inventory slot by simply calling the constructor:

InventorySlot slot1 = new InventorySlot(false, "Slot 1");
 
PREVIOUS NEXT
Tagged: #unity #struct
ADD COMMENT
Topic
Name
4+9 =