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 /
avatar image
0
Question by Envy_games · Apr 02, 2017 at 10:05 AM · cameramultiplayermultiplayer-networkingcamera-lookmultiplayer networking

Multiplayer camera problem

I've been struck, by the apparently infamous multiplayer camera problem. I have read and researched, but I can not find a solution. I have probably spent around 7-9 hours trying to get eh cameras to work. I have a simple multiplayer game, where there are two forklifts that try and flip each other over, but when the second player spawns in the first player uses their camera. I am relatively new to coding in C#, and wanted to use this as a good learning opportunity. Here is the code I have attached to the camera of my prefab as of writing this: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking;

 public class caselupa : NetworkBehaviour {
 
     // Use this for initialization
     void Start () {
         if (!gameObject.transform.parent.gameObject.GetComponent<NetworkView>().isMine)
         {
             gameObject.SetActive(true);
         }
     }
     
     // Update is called once per frame
     void Update () {
         if (!gameObject.transform.parent.gameObject.GetComponent<NetworkView>().isMine)
         {
             gameObject.SetActive(true);
         }
     }
 }
 

As I said I am relatively new to C#, and so I tried using other peoples' code, and it would not work, so I took what info I could gather, and made that bit of code. The way I understand it, if the network view of the parent object is not owned by the local player then don't use that camera. Any help I could get would be great, It is 9:00 now and I have been working on this problem for the past 3 hours.

edit: about a half hour after posting this I did a little test, I just set the camera to inactive, in the inspector, and made a code that just on start set the camera as active, and every frame checked to see if the camera was active. The thing is nothing happened. So I have one of two conclusions. Either A: I am just so bad at programming that I can't set something as active, or B: the code, for whatever reason, is not affecting my game object.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lll4louis · Jun 30, 2018 at 08:28 AM

I had this problem before, and soon I find out that you should not put the camera into the Player. alt text

and in this camera, I make two script for it

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 namespace S3
 {
     public class CameraFollow : MonoBehaviour
     {
         public Transform playerTransform;
         public int depth = 0;
         // Update is called once per frame
         void Update()
         {
             if (playerTransform != null)
             {
                 transform.position = playerTransform.position + new Vector3(0, 0, depth);
             }
         }
         public void setTarget(Transform target)
         {
             playerTransform = target;
         }
     }
 }
 



and the next script

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 
 namespace S3
 {
     public class CameraController : NetworkBehaviour
     {
 
         // Use this for initialization
         void Start()
         {
 
         }
 
         // Update is called once per frame
         void Update()
         {
             float x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
             float z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
 
             transform.Rotate(0, x, 0);
             transform.Translate(0, 0, z);
         }
     }
 }
 

so, it will become a FPS game, hope it works.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to select a specific network player - photon unity networking 3 Answers

Check Standalone device network connection 0 Answers

Bullets Only Spawning on Host Client... (a uNet problem),Multiplayer Connected Client Not Spawning Bullets, But Host the is... 0 Answers

How to make private room in Photon PUN 2? 0 Answers

Setup Custom Multiplayer Joining 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