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

Question Network interaction not working / client IsOwner = false for some reason

Discussion in 'Scripting' started by Odyssean, Feb 16, 2024.

  1. Odyssean

    Odyssean

    Joined:
    Jan 20, 2023
    Posts:
    17
    Alright so:

    Long story short, I have an interaction script, where basically "if press e, that objects runs the 'interact' method". This is currently being used for doors and whatnot, but will be expanded soon.

    It is also being used to pilot around a little ship that is displayed on a screen. Currently, it works for the host, but not the client. Here is what I currently have:

    Code (CSharp):
    1.     public void Interact()
    2.     {
    3.         piloting = true;
    4.         this_player = GameObject.FindWithTag("Player");
    5.  
    6.         Debug.Log("Is Owner = " + IsOwner);
    7.     }
    8.  
    9.     void Update()
    10.     {
    11.         if (piloting == true && IsOwner == true)
    12.         {
    13.             this_player.GetComponent<PlayerController>().enabled = false;
    14.             this_player.GetComponent<PlayerLook>().enabled = false;
    15.  
    16.             if (Input.GetKey("w"))
    17.             {
    18.                 Debug.Log("Pressing W");
    19.                 ship.transform.Translate(0, 0, 10f * Time.deltaTime);
    20.             }
    21.             if (Input.GetKey("s"))
    22.             {
    23.                 ship.transform.Translate(0, 0, -10f * Time.deltaTime);
    24.             }
    25.  
    26.             if (Input.GetKey("a"))
    27.             {
    28.                 ship.transform.Rotate(0, -50f * Time.deltaTime, 0);
    29.             }
    30.             if (Input.GetKey("d"))
    31.             {
    32.                 ship.transform.Rotate(0, 50f * Time.deltaTime, 0);
    33.             }
    34.  
    35.             if (Input.GetKeyDown("e"))
    36.             {
    37.                 this_player.GetComponent<PlayerController>().enabled = true;
    38.                 this_player.GetComponent<PlayerLook>().enabled = true;
    39.                 piloting = false;
    40.             }
    41.         }
    42.  
    43.  
    44.     }
    45. }
    The weird thing is:
    only when this script runs does it say that a client isnt the owner of their machine, but it does every single other update function. If i get rid of the "If IsOwner", everything runs, W is pressed, but the ship never moves.

    Everything has network interraction, variables, transforms, etc. Any ideas? Thanks in advance!
     
  2. wechat_os_Qy01JZm0AaUK833l6DhAKjWvQ

    wechat_os_Qy01JZm0AaUK833l6DhAKjWvQ

    Joined:
    May 3, 2024
    Posts:
    1
    S***,now i meet the same problem,client `s IsOwner aways print false,i`m just a rookie by the way