How do I fix this?!?! this is my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using TMPro;
public class Player : NetworkBehaviour
{
[Header(“Player Movement Values:”)]
[SerializeField] float moveSpeed = 5;
[SerializeField] float jumpForce = 5;
[Header(“Player Information”)]
[SyncVar(hook = “handleDisplayNameUpdated”)] [SerializeField] private string displayName = “Missing Name”;
[SyncVar(hook = “handleDisplayColourUpdated”)] [SerializeField] private Color Color = new Color(1,1,1,1);
[Header(“References:”)]
[SerializeField] SpriteRenderer sr;
[SerializeField] Rigidbody2D rb;
[SerializeField] TMP_Text displayNameText;
private void Update()
{
handleMovement();
}
#region Player Movement
void handleMovement()
{
if (isLocalPlayer)
{
float mx = Input.GetAxisRaw("Horizontal");
transform.position = new Vector3(transform.position.x + mx * Time.deltaTime * moveSpeed, transform.position.y);
if (Input.GetKeyDown(KeyCode.W))
{
rb.velocity = transform.up * jumpForce;
}
}
}
#endregion
#region Server
[Server] // [server] not needed it just prevents client from calling it
public void setDisplayName(string newDisplayName)
{
if (newDisplayName == "Frick") { return; }
else
{
displayName = newDisplayName;
}
}
[Server] // [server] not needed it just prevents client from calling it
public void setVisibleColor(Color newColor)
{
Color = newColor;
}
[Command] //Command: For CLIENTS CALLING a method ON THE SERVER
private void CmdSetDisplayName(string newDisplayName)
{
RpcLognewName(newDisplayName);
setDisplayName(newDisplayName);
}
#endregion
#region Client
private void handleDisplayNameUpdated(string oldName, string newName)
{
displayNameText.text = newName;
}
private void handleDisplayColourUpdated(Color oldColor, Color newColor)
{
sr.color = newColor;
}
[ContextMenu("Set My Name")]
public void setMyName()
{
CmdSetDisplayName("My New Name");
}
[ClientRpc] //Ran On the Client Called by the server - Client Rpc's are for the SERVER calling a method on ALL CLIENTS
private void RpcLognewName(string newDisplayName)
{
Debug.Log(newDisplayName);
}
#endregion
}