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?
This is a javascript that is called playercontroller.js and is attached to a player prefab that changes name. And no class since its javascript.
Answer by Alec-Slayden · Jun 02, 2016 at 10:53 AM
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.
So after editing my Unityscript accordingly to your advice I get a very similar error. The current script looks like this:
function OnCollisionEnter(collision : Collision) {
if (canattack)
{
if (other.gameObject.CompareTag("Player"));
{
if(col.collider.other.GetComponent("PlayerControl"))
{
var otherPlayer : Player = col.collider.other.GetComponent("PlayerControl");
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.Send$$anonymous$$essage ("Damage", damage,Send$$anonymous$$essageOptions.DontRequireReceiver);
}
}
}
}
}
and now it's telling me that its still Player missing wich means it's on line 32. What does that actually stand for? Cause I have this script connected to the character. It's called Sword.js. And it contains what i pasted above. Then on my PlayerControl script that is also sitting on my player I have this Stun function and all that. What do I replace player with after "var otherPlayer : . I dont fully understand the syntaxing here. can you possibly help me out?
I am not sure which line line 32 is, but you are still casting 'otherplayer' as type Player when you define it. If after fixing that there are more errors, also point out the actual line of code it refers to since the line might be different from what's shown here
How would one fix that? is player a object and not variable?