Hello, i need help with unity and multiplayer 3D

Hi, I’m new to this exciting world of programming and it’s very exciting for me.
I really hope that we have pleasant conversations, and that you have patience with someone who is completely new here, and in programming in general.

I’m trying to make a multiplayer game. watch this tutorial here:

I have the following error

Assets\Scripts\PlayerController.cs(87,1): error CS1022: Type or namespace definition, or end-of-file expected

here is the code from PlayerController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;

[RequireComponent(typeof(CharacterController))]

public class PlayerController: NetworkBehaviour
{
    public float walkingSpeed = 7.5f;
    public float runningSpeed = 11.5f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;
    public Camera playerCamera;
    public float lookSpeed = 2.0f;
    public float lookXLimit = 45.0f;

    CharacterController characterController;
    Vector3 moveDirection = Vector3.zero;
    float rotationX = 0;

    [HideInInspector]
    public bool canMove = true;

    void Start()
    {
        characterController = GetComponent<CharacterController>();

        // Lock cursor
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;


        if (!isLocalPlayer)
        {
            playerCamera.gameObject.SetActive(false);
        }
    }
         
           
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }
             }
        // We are grounded, so recalculate move direction based on axes
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        Vector3 right = transform.TransformDirection(Vector3.right);
        // Press Left Shift to run
        bool isRunning = Input.GetKey(KeyCode.LeftShift);
        float curSpeedX = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Vertical") : 0;
        float curSpeedY = canMove ? (isRunning ? runningSpeed : walkingSpeed) * Input.GetAxis("Horizontal") : 0;
        float movementDirectionY = moveDirection.y;
        moveDirection = (forward * curSpeedX) + (right * curSpeedY);

        if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
        {
            moveDirection.y = jumpSpeed;
        }
        else
        {
            moveDirection.y = movementDirectionY;
        }

        // Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
        // when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
        // as an acceleration (ms^-2)
        if (!characterController.isGrounded)
        {
            moveDirection.y -= gravity * Time.deltaTime;
        }

        // Move the controller
        characterController.Move(moveDirection * Time.deltaTime);

        // Player and Camera rotation
        if (canMove)
        {
            rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
            rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
            playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
            transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
        }
    }
}

You have an extra } bracket on line 47, remove it.

1 Like

wow! Yes, it works now … I’m amazed how you found out where the problem is, it doesn’t say line 47 anywhere? or you see the whole code and see where the error is? Thank you very much !!!

With a little experience, you’ll too be able to spot mismatched brackets by browsing the code. Seeing a } at its own indent level was the first tip. And to your credit, you properly used Code Tags to make it easier to spot, so thanks!

1 Like

I hope to reach at least half of your level, and I will be very happy! Now I have a new problem, when I press the run button in the toolbar of Unity, the game starts, but when I try to build it I have this code.

I am a complete beginner …

NetworkManager has a NetworkIdentity component. This will cause the NetworkManager object to be disabled, so it is not recommended.
UnityEngine.Debug:LogError (object)
Mirror.NetworkScenePostProcess:OnPostProcessScene () (at Assets/Mirror/Editor/NetworkScenePostProcess.cs:37)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()

Generally you want to open a new thread for a new bug. This helps other users who are browsing the forum with a similar problem. Keep in mind that multiplayer is quite advanced, you might want to go through a few tutorials and create your game in single player mode first.

1 Like

Okey, Thank you !!!