Identical scripts, but only one works

Hi so I’m making two simple scripts. A player damages enemy script and an enemy damages player.

In my player damage → enemy script (Attached to player) I have the following code that works fine:

 if (hit.collider.gameObject.tag == ("Enemy")) 
var eh : EnemyHealth = hit.collider.gameObject.GetComponent("EnemyHealth");

In my enemy damage → player(Attached to Enemy) I have:

#pragma strict
var Player : GameObject;
function Update () 

var distance = Vector3.Distance(Player.transform.position, gameObject.transform.position);

if(distance < 15)
    var ph : PlayerHealth = Player.GetComponent("PlayerHealth");
    ph.ApplyDamageToPlayer ();

Here’s the error:

Assets/Scripts/EnemyTest.js(13,18): BCE0018: The name ‘PlayerHealth’ does not denote a valid type (‘not found’).

I don’t really notice any difference in the code between the two?

Also, PlayerHealth is written in c#, but I don’t think that should matter right?

Having PlayerHealth written in C# is a problem. Javascript files are compiled before C# files. In order to reference the C# file, you will need to get the PlayerHealth script to compile first. The typically suggested solution is to move PlayerHealth into the Standard Assets folder. You will find a bit more about order of compilation here:

Note I recommend you use the non-string version of GetComponent by removing the quotation marks:

var ph : PlayerHealth = Player.GetComponent(PlayerHealth);