How to get a custom component declared by variable?
This is basically what I want:
public Component theComponent;
public GameObject objToAnswer;
public Color color;
public void Finished()
{
objToAnswer.GetComponent<theComponent>().ReturnColor(color);
}
Return.requestComponentBehaviour' is a "field" but a "type" was expected
I understand that I can't do this way, but there's another approach to achieve this result, I mean getting a custom component?
Also, just to clarify, the component would then be set in Unity Editor, so I guess I can't cast as something, because I don't know what would be anyway.
Answer by Cuttlas-U · Oct 04, 2017 at 04:40 AM
hi;
public Behaviour component;
with this u can assing any component to the editor;
but i think u can just enable or disable it this way ;
if u want to run function or do any thing u have to check for the compoennt Type :
Yeah. I can't get the component or anything else except disabling and enabling the component. Thanks for answering. Do you think it's possible to get a component dinamically somehow? Or Unity can't do this?
Your answer
Follow this Question
Related Questions
Adding created component to game object. 0 Answers
What to use instead of GameObject.Find and GetComponent 2 Answers
How to correctly handle NullReferenceException when using GetComponent<>? 1 Answer
Unable to correctly use game objects? 2 Answers
Game Manager can't decide what the instance of the object is despite just making an instance of it 1 Answer