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 alpha-ro · Aug 30, 2013 at 05:19 AM · multiplayerplayerprefabsdisablenetworkview

How can assign just 1 specific prefab to 1 specific player?(Multiplayer)

Hi, i'm having a lot of troubles to get the basis of my game to work correctly, and i think that is because i'm trying to run all players with the same prefab. You see..., 1 player controls all the players (mouselook, movement, even the pause menu, etc), so i tried converting my scripts to Multiplayer using codes such as:

 function Awake ()
 {
     if(!networkView.isMine)
     {
         enabled=false;
     }
     else
     {
         enabled=true;
     }
 }

In the example above, i applied the code (in a specific script) to the main camera of my unique prefab which i'm trying to instantiate and control properly in a server, but as soon as i try to connect from a standalone parallel client, the client's camera gets disabled (that's exactly the opposite of what i want), leaving only the server's camera enabled.

In other threads and forum topics i read that is not very suitable to try to run all the players with a unique prefab, so now i want each player to have a unique prefab (and hopefully make the work a bit easier), but i don't know how to accomplish this...

The maximum amount of players in my game would be 4, so i think i must differenciate them along all the sessions in a way or another...maybe setting a unique networkView ID for each player? how can i set an ID? and then...enable/disable objetcs or scripts according to IDs?

I'm short of ideas, i'm starting to hate multiplayer programming, the only thing i got is to open and connect to a server :P

Well, thanks in advance!

Comment
Add comment · Show 1
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 AdenFlorian · Aug 30, 2013 at 06:00 AM 0
Share

This would be a good tutorial to learn more about the basics of unity networking:

http://cgcookie.com/unity/2011/12/20/introduction-to-networking-in-unity/

It covers the issue you are having with having multiple player prefabs that are all getting controlled by one player. You seem to be on the right track with networkView.is$$anonymous$$ine. There is no turnkey solution to this, and it requires a decent understanding of how unity networking works to know where to use networkView.is$$anonymous$$ine.

To start, in the player control script, wrap the block of code that takes the user input to move the character with the following if statement:

 if (!networkView.is$$anonymous$$ine) {
     // $$anonymous$$ovement code
 }

This makes it so players only move their own characters.

You might also have camera conflicts. To get around that you could use the same if statement as before in the awake function to disable the camera component on a player prefab if it does not belong to the player.

The more complex your characters are, the more places you will have to use that if statment to turn things off.

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Should you disable NetworkView when offline 1 Answer

Camera attached to the wrong player 1 Answer

How to manually handle multiplayer prefabs spawning with our own script ? 0 Answers

How do I update player tilt in multiplayer? 0 Answers

How to update NetworkView on child transform when only the parent is moving? 1 Answer


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