Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TwoTen · Jun 02, 2016 at 10:08 AM · colliderissues

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);
                    
              }
              
          }
  }
  }
      
      
                }


Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Alec-Slayden · Jun 02, 2016 at 10:29 AM 0
Share

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?

avatar image TwoTen Alec-Slayden · Jun 02, 2016 at 10:34 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TwoTen · Jun 02, 2016 at 10:58 AM 0
Share

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.

avatar image TwoTen · Jun 02, 2016 at 11:57 AM 0
Share

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?

avatar image Alec-Slayden TwoTen · Jun 02, 2016 at 06:28 PM 0
Share

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

avatar image TwoTen Alec-Slayden · Jun 02, 2016 at 06:33 PM 0
Share

How would one fix that? is player a object and not variable?

Show more comments
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

enable and disable character's colliders in specific moments. 0 Answers

How would I change material properties of a box collider via script? 0 Answers

Triggers colliding with triggers 1 Answer

Need to move gameObject when triggering collider 0 Answers

It lags when it collides. Help? :( 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges