Hey! Im following a tutorial about an easy inventory system.
My problem: I try to access a sprite decleration in inventory.cs from slot.cs.
Heres the Inventory.cs Script (i comment the line where the issue appears:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class SlotNew : MonoBehaviour {
private Stack<Item> items;
public Text stackText;
public Sprite slotEmpty;
public Sprite slotHighlight;
// Use this for initialization
void Start () {
items = new Stack<Item> ();
RectTransform slotRect = GetComponent<RectTransform> ();
RectTransform txtRect = GetComponent<RectTransform> ();
int txtScaleFactor = (int)(slotRect.sizeDelta.x * 0.60);
stackText.resizeTextMaxSize = txtScaleFactor;
stackText.resizeTextMinSize = txtScaleFactor;
txtRect.SetSizeWithCurrentAnchors (RectTransform.Axis.Vertical, slotRect.sizeDelta.y);
txtRect.SetSizeWithCurrentAnchors (RectTransform.Axis.Horizontal, slotRect.sizeDelta.x);
}
// Update is called once per frame
void Update () {
}
public void AddItem(Item item)
{
items.Push (item);
if (items.Count > 1) {
stackText.text = items.Count.ToString ();
}
ChangeSprite (item.spriteNeutral , item.spriteHighlight); **<-- spriteNeutral and spriteHighlight are RED.**
}
private void ChangeSprite(Sprite neutral, Sprite highlight)
{
GetComponent<Image> ().sprite = neutral;
SpriteState st = new SpriteState ();
st.highlightedSprite = highlight;
st.pressedSprite = neutral;
GetComponent<Button> ().spriteState = st;
}
}
and here the slot.cs Script
using UnityEngine;
using System.Collections;
public enum ItemType{MANA, HEALTH};
public class ItemNew : MonoBehaviour {
public ItemType type;
public Sprite spriteNeutral; **<-- i try to access this**
public Sprite spriteHighlight; **<-- and this**
public int maxSize;
public void Use()
{
switch(type)
{
case ItemType.MANA:
Debug.Log("I just used mana potion");
break;
case ItemType.HEALTH:
Debug.Log("I just used health potion");
break;
}
}
}
i´ve tried almost everything possible and it seems no one else has the same problem i do in this tutorial. Link to the tutorial and the right part where he talks about this function: Unity Tutorial: Creating an inventory(PART 1) - The basic functionality - YouTube
Any ideas why i cant access it? Mono says: “Item” does not contain a definition for spriteNeutral.