Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Third Party PUN 2 - Why is my "IsMine" returning false if in the editor it says its true?

Discussion in 'Multiplayer' started by theokiwi, Jan 27, 2024.

  1. theokiwi

    theokiwi

    Joined:
    Jul 2, 2020
    Posts:
    4
    Im trying to stop the two online characters to move with the same input. They move in different ways so they which have their own movement code and they come from the abstract class IMovement. I've tried changing it back to MonoBehaviour but it didn't work.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5.  
    6. public class PuzzlerMovement : IMovement
    7. {
    8.  
    9.     public PhotonView pv;
    10.     public float speed = 5.0f;
    11.  
    12.     private IMovement p_movement;
    13.  
    14.     void Awake(){
    15.     if(pv = GetComponent<PhotonView>()){
    16.         Debug.Log("Got component");
    17.     }
    18.     }
    19.  
    20.     void Start(){
    21.      if(!pv.IsMine){
    22.          Debug.Log("PV is not mine");
    23.          p_movement = GetComponent<IMovement>();
    24.          p_movement.enabled = false;
    25.     }
    26.     }
    27.  
    28.     void Update()
    29.     {
    30.     float vertical = Input.GetAxis("Vertical");
    31.     float horizontal = Input.GetAxis("Horizontal");
    32.  
    33.     Vector3 dir = new Vector3(horizontal, 0f, vertical).normalized;
    34.  
    35.     transform.Translate(dir * Time.deltaTime * speed);
    36.     }
    37. }
    38.  
    I'm confuse because in the Spawned Prefab editor PhotonView attribute says that: IsMine: true.

    Why is it always returning false? How do i make it return true? Is there another way to make the movements not overlap?

    Obs: They are being spawned with a PhotonNetwork.Instantiate and they do have a view ID.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,076
    In worst case, using IsMine is too early in the Start method.
    You need to debug, step by step. E.g. add output to the log which shows the return of GetComponent<IMovement>() and if there is another.
    Your script may disable a different component but still be enabled itself.