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 jkindle88 · Nov 27, 2011 at 01:17 AM · cameranetworkingswap

Networking - Camera Swapping to Target Incorrect Player

I spawn a prefab that has an camera child and the player should just see through that camera. If there's just one player on the network, he has the right cam, but when the second player joins, he changes his camera with the one from him. Each camera is a child of each player. I use a prefab, and the camera begins disabled. I attempt to enable it in the player script with the following code:

 function Awake(){
     GetComponent(Camera).enabled = true;
 
 }

However, I'm still getting this strange result. When I add a second player to the game, the first player's camera gets moved to the second player, while the second player's camera follows the first player, but the controls are correct. In short, the cameras swap places.

Should I change my camera setup, or is there a way to make this work? Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by syclamoth · Nov 27, 2011 at 01:36 AM

You need to check for if the camera is local!

 function Awake() {
     if(networkView.isMine)
     {
         camera.enabled = true;
     }
 }

If the camera script itself doesn't have a network-view component, use the one from the player instead.

Comment
Add comment · Show 1 · 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 owenoliver1 · Jul 22, 2013 at 05:37 PM 0
Share

You didn't mention that you need to add the camera then disable it so that this code will work but thank you :)

avatar image
0

Answer by gevarre · Dec 08, 2011 at 08:49 AM

I've got the same situation: I've got a prefab vehicle (named HoverRig_Prefab) with a camera further down in the hierarchy. The top level node has the network-view component and I put your camera-enabling code also on the top node, but when I start the game, I get this error message:

MissingComponentException: There is no 'Camera' attached to the "HoverRig Prefab(Clone)" game object, but a script is trying to access it. You probably need to add a Camera to the game object "HoverRig Prefab(Clone)". Or your script needs to check if the component is attached before using it.

I'm not sure what you mean by using the network-view component from the player, but could that be the problem, or do I need to do something else?

Comment
Add comment · Show 1 · 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 owenoliver1 · Jul 22, 2013 at 05:36 PM 0
Share

You need to add a camera onto the HoverRig then disable it. If you mean in the code then make sure you use camera not Camera they are different

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

mirror player camera using one camera 0 Answers

Swapping between Diffuse and Transparent/Diffuse Shaders 0 Answers

Broadcast camera render over network 2 Answers

Multiplayer camera switch issue 0 Answers

How to set up multiple cameras for multiplayer 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