0
votes

I am testing out the Unet multiplayer functionality on a basic 2d game. At the moment it consists of a single box/racket moving up and down. In the monobehaviour class the box moves up and down correctly, however when i include the islocalplayer in the networkbehaviour class the box does not move up and down. When I play the game the network information box says islocal no. How do i go about changing this. enter image description here

using UnityEngine;
using UnityEngine.Networking;

public class MoveRacket : NetworkBehaviour
{
  public float speed= 30;
  public string axis = "Vertical"; 

  void Update()
  {

    if (!isLocalPlayer)
    {
       return;
    }

    float v = Input.GetAxisRaw(axis);
    GetComponent<Rigidbody2D>().velocity = new Vector2(0, v) * speed;
  }

}
2

2 Answers

0
votes

ok got it in the network manager game object > spawn information > check auto create player

0
votes

isLocalPlayer is in the NetworkObject file, try to open the NetworkObject script and find:

public bool IsLocalPlayer => NetworkManager.Singleton != null && IsPlayerObject && OwnerClientId == NetworkManager.Singleton.LocalClientId;

if it is there you should change isLocalPlayer to IsLocalPlayer.