- Home /
Question by
is4kduude · Apr 16, 2020 at 11:55 AM ·
c#scripting problemprogrammingclasses
How do I reference a class to pass on variables in that class?
I am making an inventory for a game but cant get a reference from a script holding my item data to my inventory script working.
Here is my item data script:
public class BootsData : MonoBehaviour
{
private ItemCalculation itemCalculation;
private UIEditor uIEditor;
public Items[] items = new Items[4];
private void Start()
{
itemCalculation = GameObject.FindObjectOfType<ItemCalculation>();
uIEditor = GameObject.FindObjectOfType<UIEditor>();
}
public void SendDataToUIEditor (int[] IDs)
{
for (int i = 0; i < IDs.Length; i++)
{
UIEditor.GetItemData(items[IDs[i]]);
}
}
In the same script I have a different class for the data:
public class Items
{
public string name;
public float armour;
public float speedIncrease;
public Sprite inventoryItem;
public GameObject physicalItem;
public enum itemClass {boots, chestplate, pants, gloves, belt, ring, bracelet, weapon, miscellaneous};
}
the second script I have is my UI Controller:
public class UIEditor : MonoBehaviour
{
public void GetItemData (Items item)
{
Debug.Log(item);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Help me finish my room generator 0 Answers
Static variable work in one script but not in the other 1 Answer
How to shorten multiple if statements ? 2 Answers
Distribute terrain in zones 3 Answers