|
Hi, I have this piece of code: var enemyScript = hit.transform.GetComponent(scriptEnemy); When run, the console says "'numberOfClicks' is not a member of 'UnityEngine.Component'. " When it is declared as follows in scriptEnemy out with any functions: Anyone know whats happening here? Thanks, Jack
(comments are locked)
|
|
The error is correct--numberOfClicks is, indeed, not a member of Component at all. It's a member of your script. Your script is a Component, but a Component is not your script; that's known as inheritance. I assume you're not using Unity 3.4, because otherwise " I was wondering if hit.transform.GetComponent would even work, hadn't tried it like that instead of hit.gameObject.GetComponent... so, .transform will work like that too?
Dec 21 '11 at 10:45 PM
Lo0NuhtiK
Yes, Transform has tag as an inherited variable and GetComponent as an inherited function. Not sure what you mean about the tag not being in quotes; presumably tagName and tagName2 are strings and you don't put variable names in quotes. (Although CompareTag is preferable to using == comparisons.)
Dec 21 '11 at 11:12 PM
Eric5h5
Ok... didn't know transform would work those ways. Thanks.
Dec 21 '11 at 11:22 PM
Lo0NuhtiK
(comments are locked)
|
