How to get the component in a new class
Hey guys, here is the script:
[System.Serializable]
public class main
{
public GameObject Prefab;
public Text Btn_Text;
public Color color;
}
public class StoreManager : MonoBehaviour
{
//All the lists in the script
[Header("All the lists")]
public List<main> Main = new List<main>();
//Ends here
I need to set the color of the gameobject prefab as the color of the color variable. when I use GetComponent it doesn't work. what can I do right now?
Any help would be appreciated
A $$anonymous$$onoBehaviour class inherits the Component class( Technically Behaviour then it inherits Component. The main class does not derive/inherit from $$anonymous$$onoBehaviour and thus is missing the Component class to match when using GetComponent method. GetComponent will not find the main class from a call like
GetComponent<main>()
Your answer
Follow this Question
Related Questions
Accessing Variables inside classes inside other classes? 1 Answer
Game Manager can't decide what the instance of the object is despite just making an instance of it 1 Answer
C# Find specific object by getting one of its variables 0 Answers
Custom class, Null Reference Exception 4 Answers
(SOLVED) Accessing (string) arrays by enumerations from another class 0 Answers