I'm Able To Control The Other Player

For some reason, when I use the simple if view.IsMine thing, I'm able to control the other player, not my own, I'm doing it in 3D btw

Answers

  • Klover
    Klover ✭✭

    show us your code

  • Alrighty, Here It is

    using UnityEngine;

    using Photon.Pun;


    public class Move : MonoBehaviour

    {

      public CharacterController controller;

      public float speed = 12f;


      public float gravity = -1.81f;

      public float jumpHeight = 3f;


      public float jumpCooldown = 1.6f;

      public float jumpC;


      public bool noJumping;

      PhotonView view;

      Vector3 velocity;

      void Start()

      {

        view = GetComponent<PhotonView>();

      }   

      void Update()

      {

         

        if (view.IsMine)

        {

          if (noJumping == false)

          {

            jumpC += Time.deltaTime;

          }

          float x = Input.GetAxis("Horizontal");

          float z = Input.GetAxis("Vertical");


          Vector3 move = transform.right * x + transform.forward * z;


          controller.Move(move * speed * Time.deltaTime);


          velocity.y += gravity * Time.deltaTime;


          controller.Move(velocity * Time.deltaTime);

          if (Input.GetButtonDown("Jump") && jumpC >= jumpCooldown)

          {

            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);

            jumpC = 0;

          }

          if (Input.GetButtonDown("Jump") && transform.position.y <= -1)

          {

            jumpC = 0;

            noJumping = true;

          }

        }

      }

    }

  • Oh yeah, I forgot the spawning script too, just in case that'll help


    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    using Photon.Pun;


    public class SpawnPlayers : MonoBehaviour

    {

      public GameObject pre;

      public float minX;

      public float maxX;

      public float minZ;

      public float maxZ;


      private void Start()

      {

        Vector3 randomPostition = new Vector3(Random.Range(minX, maxX), 10, Random.Range(minZ, maxZ));

        PhotonNetwork.Instantiate(pre.name, randomPostition, Quaternion.identity);

      }

    }