The name 'Player' does not denote a valid type ('not found')

So I had some trouble getting some things to work and got fairly good answers over at this post.
The only issue I had occured when trying to translate the C# code that the gentleman provided into Javascript. I now get the error stated in the title. I’m assuiming it’s because Player is not a valid object. But my player prefab, once spawned gets a UNIQUE name from ALL other players with the SAME prefab. So i cannot just replace Player with the name of the prefab since they all have a unqiue one. I hope I could get some help solving the follwing issue,

function OnCollisionEnter(collision : Collision)
{

         if (canattack)
         {
         if (other.gameObject.CompareTag("Player"));
         {
         if(col.collider.other.GetComponent("Player"))
         {
          var otherPlayer : Player = col.collider.other.GetComponent("Player");
         if(otherPlayer.isBlocking)
         {
         this.Stun ();
         }
         else
         {
         otherPlayer.Damage(damage);
         }
             
 
             for (var contact: ContactPoint in collision.contacts)
             {
                 var impact = Instantiate(impactPrefab, contact.point, Quaternion.FromToRotation(Vector3.up,contact.normal));
                 collision.gameObject.SendMessage ("Damage", damage,SendMessageOptions.DontRequireReceiver);
                   
             }
             
         }
 }
 }
     
     
               }

just to clarify, this is on a script named Player, in a class named Player and you do not have a C# Player script currently, correct?

Why not just use the standard shader and set the emission channel? With a bloom effect on your camera (and HDR enabled) you should see them glow.

1 Answer

1

The error you’re getting means it can’t find a class, specifically the class named “Player” that you are getting in lines 5 and 7.

I notice that the solution you were translating from the old answer was a C# class called “Player”, however you are translating it into a unityscript class called playercontroller.

This means one of two things is probably happening:

  1. Most likely, you simply need to update your sript to reflect the changes to the class name as you translated. Instead of getting the Player component, now it should be playercontroller (or whatever your script name is). Be careful, however, not to change the tag comparison accidentally.

  2. This probably isn’t the case, but If you do actually have an existing Player.cs c# script around and are intentionally looking for it in this script, then you are likely experiencing problems from compilation order. the playercontroller wouldn’t know that Player.cs exists unless Player is compiled first if they’re different languages. The cleanest solution would be to maintain one language between the two scripts, but if that’s not desirable or efficient right now, you can also place the Player c# script in a Plugins folder, as per the link, to ensure it is compiled first, and therefore found by the unityscript.

Thank you very very much good sir! I am very new to unity and I will get back to you once i've tested this.

can i apply it on specific prefabs using scripts? What I mean is can i turn it on and off?