x


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!!!");}
more ▼

asked Oct 31 '10 at 01:58 AM

Matt 15 gravatar image

Matt 15
149 18 19 26

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first
if ( (hit.collider.GetComponent(touchingThreeScore) as touchingThreeScore).idNumber == 
     (thisTransform.GetComponent(touchingThreeScore) as touchingThreeScore).idNumber) {

Although probably you'd want to cache "thisTransform.GetComponent(touchingThreeScore)".

more ▼

answered Oct 31 '10 at 03:31 AM

Eric5h5 gravatar image

Eric5h5
80.1k 41 132 519

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!

Oct 31 '10 at 05:11 AM Matt 15

@Matt: var script = thisTransform.GetComponent(touchingThreeScore) as touchingThreeScore; The type is the same as the script name.

Oct 31 '10 at 03:44 PM Eric5h5
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Oct 31 '10 at 03:51 AM

Jessy gravatar image

Jessy
15.6k 72 95 196

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.

Oct 31 '10 at 04:29 AM Eric5h5

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?

Oct 31 '10 at 01:59 PM Jessy

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.

Oct 31 '10 at 03:51 PM Eric5h5

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.

Oct 31 '10 at 04:30 PM Jessy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1999
x405
x111
x96
x9

asked: Oct 31 '10 at 01:58 AM

Seen: 5686 times

Last Updated: Aug 14 '11 at 08:01 AM