im trying to change the color of some text using the script, however it dosent see to be working, here is my code
GetComponent(Text).color = Color.green;
i am getting multiple issues because of this code, please could someone explain why.
im trying to change the color of some text using the script, however it dosent see to be working, here is my code
GetComponent(Text).color = Color.green;
i am getting multiple issues because of this code, please could someone explain why.
Use the generic form instead. The non-generic only returns an object of type Component, which doesn’t have a color property.
Like so:
GetComponent<Text>().color = Color.green;
GetComponent(Text)
returns a Component
.
You need to cast it back to Text type.
(Text)GetComponent(Text);
You can also simply use the generic implementation
GetComponent<Text>();
Which will return the component as the type it is given (Text).