- Home /
Duplicate Question
Calling Enemy Health Adding to Player Score
I have one problem lately I cannot figure out, and though there are many of the same questions as to calling other scripts, nothing seems to fit my particular situation. I have these two scripts, and I am trying to get either one to call the other and add to the player score when the enemy is hit. Can someone help me here?
enemyHealth script
var enemyHealth = 5.0; var destroyedParticles : Transform;
function Start () {
}
function Update () {
if(enemyHealth == 0.0) {
Instantiate(destroyedParticles, transform.position, transform.rotation);
Destroy(gameObject); } } function OnGUI (){
GUI.Box(Rect(10, 50, 135, 25),"Enemy 1 Health: " + enemyHealth);
}
function OnCollisionEnter(projectileCollision : Collision) { if(projectileCollision.transform.name == ("PlasmaBall(Clone)")) { enemyHealth -=1; }
}
playerScore script;
var guiScore : GUIText; private var score : int = 0;
function Start () { guiScore.text = "Score: 0"; }
function Update () {
} function OnCollisionEnter(projectileCollision : Collision){ if(projectileCollision.transform.name == ("PlasmaBall(Clone)")){
score += 10;
guiScore.text = "Score: " + score;
}
if(score == 3000){ Application.LoadLevel("3PS_scn2"); }
}
???
I'm trying to have an empty GameObject in each level with the playerScore script on it that can sense the collisions or if the enemy is destroyed and updates the player's score basically, is what I'm trying to do. Any help would be greatly appreciated. I've had to really work to even get to this point.
Please format your code when posting questions.
http://unitygems.com/script-interaction-tutorial-getcomponent-unityscript/
There are thousands of examples on using Getcomponent to access variables on Script B from Script A; please review.
Follow this Question
Related Questions
Checking for a value overtime 2 Answers
GUI text not updateing 1 Answer
Creating a Lifebar with simple GUI in C# 3 Answers
How to add score/health ? 2 Answers
Using images to show numbers 1 Answer