Photon characters control wrong player

My code:
public bool CanMove = true;
Camera camera;
public GameObject PlayerPref;
public PhotonView view;
public float FasterSpeed = 20f;
public float JumpHeight;
public float Speed = 10f;
public CharacterController controller;
public bool IsGrounded;
public Transform Groundcheck;
public LayerMask Ground;
public float Gravity = -9.2f;
private Vector2 velocity;
public float groundDistance;
private Vector2 SmoothMove;
// Start is called before the first frame update
void Start()
{
view = GetComponent();
camera = GetComponentInChildren();

}

// Update is called once per frame

private void Moving()
{
IsGrounded = Physics.CheckSphere(Groundcheck.position,groundDistance,Ground);
float x = Input.GetAxis(“Horizontal”);
float z = Input.GetAxis(“Vertical”);
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * Speed * Time.deltaTime);
controller.Move(velocity * Time.deltaTime);
if (IsGrounded && velocity.y < 0f)
{
velocity.y = -2f;
}
if(Input.GetKey(KeyCode.LeftShift) && IsGrounded)
{
Speed = FasterSpeed;
}else
{
Speed = 18f;
}
if (Input.GetButtonDown(“Jump”)&& IsGrounded)
{
velocity.y += Mathf.Sqrt(JumpHeight * -2 * Gravity);
}
velocity.y += Gravity * Time.deltaTime;
}

public void Update()
{
   if (view.IsMine){
     Moving();
   }else
   {
     if (!view.IsMine && GetComponent<PlayerMovement>() != null)
        {
            Destroy(GetComponent<PlayerMovement>());
        }
   }

Please help bc player 1 is controlling player 2. And everything works fine until player 2 comes

2 Answers

2

sry its very messy

It is indeed very messy, all i can maybe say is to be sure that each client use PhotonNetwork.Instantiate on their on code.