When the 2nd person joins the game in Unity, the 2nd person uses the 1st person's camera and the 2nd

Options
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
public class AirplaneController : MonoBehaviour
{
  [SerializeField]
  List<AeroSurface> controlSurfaces = null;
  [SerializeField]
  List<WheelCollider> wheels = null;
  [SerializeField]
  float rollControlSensitivity = 0.2f;
  [SerializeField]
  float pitchControlSensitivity = 0.2f;
  [SerializeField]
  float yawControlSensitivity = 0.2f;

  [SerializeField] Camera m_camera;

  [Range(-1, 1)]
  public float Pitch;
  [Range(-1, 1)]
  public float Yaw;
  [Range(-1, 1)]
  public float Roll;
  [Range(0, 1)]
  public float Flap;
  [SerializeField]
  Text displayText = null;

  float thrustPercent;
  float brakesTorque;

  AircraftPhysics aircraftPhysics;
  Rigidbody rb;

  public GameObject kamera;
  PhotonView view;

  private void Start()
  {
    displayText = GameObject.Find("Text").GetComponent<Text>();
    aircraftPhysics = GetComponent<AircraftPhysics>();
    rb = GetComponent<Rigidbody>();
    view = GetComponent<PhotonView>();

    m_camera = kamera.GetComponent<Camera>();

    if (!view.IsMine)
    {
      m_camera.enabled = false;
    }
  }

  private void Update()
  {
    if (view.IsMine == true)
    {
      Pitch = Input.GetAxis("Vertical");
      Roll = Input.GetAxis("Horizontal");
      Yaw = Input.GetAxis("Yaw");

      if (Input.GetKeyDown(KeyCode.Space))
      {
        thrustPercent = thrustPercent > 0 ? 0 : 1f;
      }

      if (Input.GetKeyDown(KeyCode.F))
      {
        Flap = Flap > 0 ? 0 : 0.3f;
      }

      if (Input.GetKeyDown(KeyCode.B))
      {
        brakesTorque = brakesTorque > 0 ? 0 : 100f;
      }

      displayText.text = "V: " + ((int)rb.velocity.magnitude).ToString("D3") + " m/s\n";
      displayText.text += "A: " + ((int)transform.position.y).ToString("D4") + " m\n";
      displayText.text += "T: " + (int)(thrustPercent * 100) + "%\n";
      displayText.text += brakesTorque > 0 ? "B: ON" : "B: OFF";
    }
  }

  private void FixedUpdate()
  {
    if(view.IsMine==true)
    {
      SetControlSurfecesAngles(Pitch, Roll, Yaw, Flap);
      aircraftPhysics.SetThrustPercent(thrustPercent);
      foreach (var wheel in wheels)
      {
        wheel.brakeTorque = brakesTorque;
        // small torque to wake up wheel collider
        wheel.motorTorque = 0.01f;
      }
    }
  }
}

We create room from the lobby. Then the plane spawns automatically in the game scene and we can drive the plane. Now, we open the game from another client and click join. Now the cameras are messing up. At the bottom right of the clients, there is the height, speed, etc. When we press the movement keys, the bottom right screen changes and our plane moves, but this is seen on the other client's screen.

As I said, there is an error and I couldn't find the solution, please help me.

Answers

  • Nexo
    Options

    Did U try deleting the Camera?


    Just delete the camera If its not ours.

    public Gameobject Camera;
    PhotonView view;
    
    private void Start()
    {
       view = GetComponent<PhotonView>();
       if(view.IsMine == false)
       {
          Destroy(Camera);
       }
    }