0

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;
  }

}
the_big_blackbox
  • 1,056
  • 2
  • 15
  • 35

2 Answers2

0

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

the_big_blackbox
  • 1,056
  • 2
  • 15
  • 35
0

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.

Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35
WindyFeng
  • 1
  • 2