reprahkcin of Unity Snippet Repo
2/18/2019 - 7:24 PM

Class and Constructor

Demonstration of a class with default values, and also a constructor method.

using System.Collections;
using UnityEngine;

public class Item  // Unnecessary to specify any inheritance i.e. MonoBehaviour
                   // Start and Update functions are also not needed for this. 
    public int itemID = 0;    // Default values when none are given with constructor below
    public string itemName = "Unnamed";
    public string itemDescription = "No Description";

    public Item(int id, string name, string description) // Constructor function
        this.itemID = id; 
        this.itemName = name;
        this.itemDescription = description;