- Home /
Get component in iPhone
I am trying to make this work:
if (collision.gameObject.tag=="EnemyShip")
gameObject.Find("Score").GetComponent(TestScore).Score+=250;
but I get this error :
'Score' is not a member of 'UnityEngine.Component'.
Any help or points to documentation would be helpful and I will appreciate it.
Answer by Jessy · Jan 28, 2011 at 03:10 PM
Lots of links about this, already but this is what you need:
GameObject.Find("Score").GetComponent.<TestScore>().Score += 250;
Use uppercase, not lowercase, for GameObject. It's a static method.
This question, which I'd consider a potential duplicate of yours, should explain it more.
Well, now my score adds up regardless what object the projectile hits; if (collision.gameObject.tag=="EnemyShip") var thisExplosion : GameObject = Instantiate (explosion, contact.point + (contact.normal * 2.0) , Quaternion.identity); GameObject.Find("Score").GetComponent.().Score += 250; audio.clip = Bang; audio.Play(); Destroy (gameObject);
if (collision.gameObject.tag=="Water")
var thisSplash : GameObject = Instantiate (splash, contact.point + (contact.normal * 2.0) , Quaternion.identity);
GameObject.Find("Score").GetComponent.<TestScore>().Score += 10;
audio.clip
so its basically one projectile set up to instantiate various prefabs (water splash or explosion) depending on where it hits. I could probably move it on the hit objects ins$$anonymous$$d maybe?
At your "comment-code": you've forgot to open a codeblock { ... } after your if statement.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101532im_/https://answers.unity.com/themes/thub/images/avi.jpg)