- Home /
GetComponent Error
Hi,
I am working with GUITexture for Unity iPhone and I am getting this error and I am not sure what it means:
error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
and it highlights: private GUITexture fire3 = fire3obj.GetComponent(GUITexture);
I am trying to get access to the guitexture button after finding it with the tag.
Thank you very much!
Comment
Best Answer
Answer by Murcho · Dec 22, 2009 at 12:01 AM
Your example code looks like C#, and in C# you have to use the typeof keyword to pass a type.
private GUITexture fire3 = fire3obj.GetComponent(typeof(GUITexture)) as GUITexture;
I've also added a cast at the end, which is also required under C#. If the variable fire3 is null after this line of code, GetComponent was not able to find that component type on that object.