Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Zozingzeus · Jun 23, 2015 at 01:11 PM · editormultiplayerlocalduplicate

[Solved]Two Player Error

So I have made this really simple player script, which gets its controls from a Hashtable I have set up in a different script. The player always moves to the right and the controls will make it change direction. I have set up 4 different control schemes for 4 different players. When I only have 1 player in the scene it works fine, I can assign the player a player number and the control scheme changes depending on player number. Everything works perfectly. However when I duplicate the player and give them 2 different player numbers, the duplicated player will not move or react to controls.

I get these errors when duplicating the player and starting the game alt text

The 1 and 2 are a Debug.Log I put in to check that they are reciving their playernumbers correctly. However player number 2 gets a NullReference

This is the initialization code that gets executed, this is where I fetch the controls in the main Player.cs.

 void Start () {
     rigidbody = GetComponent<Rigidbody2D> ();
     controls = GetComponent<PlayerControls> ();
 
     //GET CONTROLLERS
     Debug.Log(playerNum);
     control = controls.getControls(playerNum);
     setKeys(control);
 }

and here is how the PlayerControls.cs looks like.

 void Start () {
 
     //Player1
     player1 = new Hashtable();
     player1.Add("Up", "a");
     player1.Add("Down", "d");
     player1.Add("Shoot", "s");
     player1.Add("Boost", "w");
 
     //Player2
     ....
     ....
 }
 
 public Hashtable getControls(int num) {
     if(num == 1) {
         return player1;
     } else if(num == 2) {
         return player2;
     } else if(num == 3) {
         return player3;
     } else if(num == 4) {
         return player4;
     } else {
         Debug.Log("Incorrect player number!");
         return new Hashtable();
     }
 }

planes.png (45.0 kB)
Comment
Add comment · Show 3
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 Ibzy · Jun 23, 2015 at 01:17 PM 1
Share

What is on Player.cs line 95?

avatar image Zozingzeus · Jun 23, 2015 at 02:11 PM 0
Share

On Player.cs line 95 is this:

 up$$anonymous$$ey = (string) controller["Up"];


the whole function is:

 void set$$anonymous$$eys (Hashtable controller) {
     up$$anonymous$$ey = (string) controller["Up"];
     down$$anonymous$$ey = (string) controller["Down"];
     shoot$$anonymous$$ey = (string) controller["Shoot"];
 }
avatar image Zozingzeus · Jun 23, 2015 at 02:56 PM 1
Share

I don't know why, but it works now :p I closed unity and when I tried what you commented it worked :P

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ibzy · Jun 23, 2015 at 02:23 PM

Looks like it isn't sending a Hashtable in the setKeys() call.

Try putting a check around it like this:

 if(control!=null){
     setKeys(control);
 } else {
     Debug.Log("No Control");
 }

And see what comes out?

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Local Multiplayer Camera 0 Answers

SmartFox Objects?? 0 Answers

Setting different values on editor and build 1 Answer

Duplicate Object, Lose Animation 0 Answers

MultiplayerEventSystem Same UI BUG 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