- Home /
BCE0019: is not a member of 'UnityEngine.Component' when trying to Build and Run iOS Unity
I've read through some forums, and I know the issue is related to Unity iPhone not supporting dynamic typing, but I still can't manage to get the syntax right on this one. Below is the syntax that works in standard Unity.
-- here is a snip of code, where I'm trying to test if the int "idNumber" is the same as the int "idNumber" on the object a ray is hitting where "hit" is the Raycast and "touchingThreeScore" is the name of the script attached to (and that has the variable idNumber) and the transform that is held in thisTransform
if(hit.collider.gameObject.GetComponent(touchingThreeScore).idNumber == thisTransform.GetComponent(touchingThreeScore).idNumber){ Debug.Log("You're Amazing for helping me out!!!");}
Answer by Eric5h5 · Oct 31, 2010 at 03:31 AM
if ( (hit.collider.GetComponent(touchingThreeScore) as touchingThreeScore).idNumber ==
(thisTransform.GetComponent(touchingThreeScore) as touchingThreeScore).idNumber) {
Although probably you'd want to cache "thisTransform.GetComponent(touchingThreeScore)".
This totally worked! Thank you! how would i go about caching the line you suggested? I guess my question really is, what type of item would it be? Component? or int?
Thanks again!
@$$anonymous$$att: var script = thisTransform.GetComponent(touchingThreeScore) as touchingThreeScore;
The type is the same as the script name.
Answer by Jessy · Oct 31, 2010 at 03:51 AM
Your code works fine in Unity 3. Ideally, you'd also GetComponent altogether, and use a generic list and the Find function, but UT hasn't supplied information about the appropriate syntax for lambdas in UnityScript, and I wouldn't bother with generic functions without them.
This didn't help.
His code actually doesn't work fine in Unity 3; anything with dynamic typing will fail when trying to make a build. GetComponent is slightly faster than using generics, so I wouldn't avoid it.
I'll take your word on the dynamic typing thing, but that's terrible that there's no error generated prior to building. Interesting note on the GetComponent; do you have a link to results?
When doing iOS scripts one should always put #pragma strict at the top, and that will solve the error generation problem. This used to be implicit in Unity iPhone when it was a separate app, but probably because of the cross-platform nature of Unity 3, that doesn't happen anymore. I don't have a link offhand, just some benchmarks I did.
It's not like we still don't deal with iOS projects. It doesn't affect me much, because I don't use UnityScript, but I think it's pretty lame to have to throw that pragma in now.
Your answer
Follow this Question
Related Questions
Unable to load Unity iPhone examples as scenes 1 Answer
Why does this script I got from the Unity Document site does not work? 1 Answer
dynamic typing in Unity iOS: ...not a member of 'UnityEngine.Component' 2 Answers
Ani.Mate error when port a PC game to iPhone 2 Answers
Making a GetComponent array 1 Answer