Quantcast
Viewing all articles
Browse latest Browse all 78

C# Custom Class - Declare Variable's Value

Ok, I made a custom Item class that does not inherit from MonoBehavior: using UnityEngine; using System.Collections; [System.Serializable] public class Item { public string id; public string displayName; public GameObject itemPrefab; public Texture2D displayImage; public string description; public int maxStack; [HideInInspector] public int currentStack = 1; } Notice, I set currentStack to = 1. Below is my ItemList Script. It just declares a list of the items that can be in the game. using UnityEngine; using System.Collections; public class ItemList : MonoBehaviour { public Item[] items; } I then can put the Item's attributes in the array in the Inspector. The problem is this: currentStack is set to 0. I'll take off the HideInInspector to check it, and it says 0, not 1. How do I set currentStack to always start off as 1?

Viewing all articles
Browse latest Browse all 78

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>