Checking enemy death and adding score issue Javascript

I have two separate scripts for my Player and my Enemies…how can I call to the enemy script within the player script and check to see if a specific enemy has been destroyed in order to add to the player’s score? I have 3 types of enemies in my enemy script and I want to set different numbers for when they are each destroyed.

Unity has very good documentation on how to access other Gameobjects and scripts

1

If you scroll down to the bottom it explains how to access other scripts

Well, there are thousands of ways to do this. To give you the first method that comes to mind.

  • Create a public int in the Enemy script, call it pointValue or something.
  • Set the pointValue on each enemy to its prospective value.
  • Create a public int in the Player script, call it currentPoints or something.
  • When the Enemy’s health is lower than zero, have it modify’s the Player script, and add its point value to the Player’s currentPoints.

Here’s a quick script example…

public int health = 100;
public int pointValue = 10;
public bool isDead = false;

void Update(){
 if( health <= 0 && !isDead ){
   Death();
 }
}

void Death(){
 int playersPoints = GameObject.FindGameObjectWithTag("Player").currentPoints;
 playersPoints += pointValue;
 isDead = true;
}

EDIT: sorry, i forgot we were talking Javascript. but that same logic would work anywhere. let me know if you still have troubles.