I’m in the process of converting some Javascript iphone 1.7 code to C#. Smooth sailing besides this one issue with referencing components…
JS (Working fine)
var go = hit.transform;
var comp = (go.GetComponent(objectClass) as objectClass);
var value = comp.getValue();
The go GameObject has a component attached of class objectClass, which has a public method called getValue(). The real problem is the 2nd line. I’m not sure how this should be written in C#.
Thanks for any feedback! I really appreciate it.
-d
Hey dreamora,
Thanks for the fast response. I tried that and I get this error:
error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected
Here’s the code:
Transform go = hit.transform;
objectClass comp = (go.GetComponent(objectClass) as objectClass);
int value = comp.getValue();
I also tried:
objectClass comp = go.GetComponent(objectClass);
Which gave the same error.
Thanks again,
-d
its GetComponent(typeof(objectClass)) instead of just objectClass
Thanks for the help. It got me going in the right direction. The final line was:
objectClass comp = (objectClass) go.GetComponent( typeof(objectClass) );
Thank you,
-d