- Home /
Score When Ship Bullet Hits An Enemy
Hi, I have a small minigame I'm making, It consists of a top down view of a ship, and i am able to shoot enemy's that fall down,(Kind of like Galaga) and I have run into a problem. I have a 3d Text Score system where you can run into 50 point power-ups (With the tag "50P") and get points, but I need to know how to make it to where I can shoot my ships bullet which has the tag, "shipProjectile" and when it hits the enemy ships with the tag "Enemy" I need it to give me 100 points or so. Here is my script, I hope you may be able to revise it.
Thanks, Brandon
My Script
var score = 0;
var score3DText : TextMesh;
function OnTriggerEnter( other : Collider ) {
if (other.tag == "50P") {
score += 50;
scoreText = "Score: " + score;
Destroy(other.gameObject);
score3DText.text = "Score: " + score.ToString();
}
}
Answer by ScroodgeM · Aug 26, 2012 at 06:23 PM
if i understood you correct
var score = 0; var score3DText : TextMesh;
function OnTriggerEnter( other : Collider ) {
if (other.tag == "50P") { score += 50; scoreText = "Score: " + score; Destroy(other.gameObject); score3DText.text = "Score: " + score.ToString(); } else if (other.tag == "Enemy") { score += 100; scoreText = "Score: " + score; Destroy(other.gameObject); score3DText.text = "Score: " + score.ToString(); } }
Well I appreciate you answering me,but I failed to explain that this script is on the character controller, and i used the script you gave me, and I put it in my script and the ships hit the Player and give me points, but I need the ships projectile to give me the points. How would I add the score to string on a seperate script?
your question is unclear a little. just to be sure: you need that this script will be attached to some other object and changes scores for this object?
Well I would like this script to be on the character controller, but apply to the characters projectile. Thank you for support though I appreciate your help through this problem of $$anonymous$$e.
OnTriggerEnter method will call only on object that owns trigger. so this script can't be attached to character controller and applying to trigger of projectile.
but you can make simple script with OnTriggerEnter method only that will be attached to projectile and on calling will call a method on character controller script.
Alright, but how would I make it to where it adds to the score?
Your answer
![](https://koobas.hobune.stream/wayback/20220613080136im_/https://answers.unity.com/themes/thub/images/avi.jpg)