How do I pass in a GameObject as a parameter when I'm instantiating a class?
I have a class called "Items" that have certain parameters, one of which is a GameObject. However I have trouble with this one, as I can't seem to assign it, use a reference from anywhere, or anything really that would keep it in this one script. Only "ItemObject" is not working, maxStack and ResourceType works just fine.
When I tried to just use a normal reference it wouldn't let me without making it static, but making it static meant I couldn't add it in the inspector. I tried to create a function to add it in, but when called from another script with monobehaviour attatched it still wouldn't work. I tried to ad a reference to the static class, and created another script, but nothing worked.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Items
{
public enum ResourceType
{
Nothing,
Iron_Ore
}
public ResourceType CurrentResourceType { get; protected set; }
public GameObject ItemObject { get; protected set; }
public bool Stackable { get; protected set; }
public int MaxStack { get; protected set; }
public Items(ResourceType _resourceType, GameObject _itemObject, int _MaxStack)
{
CurrentResourceType = _resourceType;
ItemObject = _itemObject;
MaxStack = _MaxStack;
}
public static Items IronOre = new Items(ResourceType.Iron_Ore,/*HERE IS WHERE THE GAMEOBJECT REFERENCE SHOULD BE*/, 100);
Your answer
Follow this Question
Related Questions
HELP --- Object reference not set to instance of an object. 0 Answers
SetActive is just working if i press twice in the first time 2 Answers
How can I put buttons on a Cube? 0 Answers
Disable mouse click on gameObject 1 Answer
Help! Script won't work. 1 Answer