Question by
IaMnOtgOoDaTpRoGrAmMiNg · Jun 26, 2020 at 06:54 PM ·
movementmultiplayermultiplayer-networkinggames
Multy Player both players are moving
if i add this if(!isLocalPlayer){return} thing none off my players can move heres my script
using TMPro; using UnityEngine; using UnityEngine.Networking;
public class player : NetworkBehaviour {
[Header("player Movement")]
[SerializeField] float moveSpeed = 5f;
[SerializeField] public float mouseSensitivity = 5f;
public Rigidbody rigidBody;
public float JumpForce;
private bool isOnGround;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "Boden")
{
isOnGround = true;
}
}
private void OnCollisionExit(Collision collision)
{
if (isOnGround == true)
{
isOnGround = false;
}
}
void Update()
{
if (!isLocalPlayer)
{
return;
}
if (Input.GetKey(KeyCode.Escape))
{
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
if (Input.GetKey(KeyCode.LeftShift))
{
moveSpeed = 7f;
}
else
{
moveSpeed = 4;
}
if (isOnGround == true)
{
Grounded();
}
Move();
}
private void Move()
{
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime);
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime);
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime);
}
private void Grounded()
{
if (Input.GetKey(KeyCode.Space))
{
rigidBody.AddForce(new Vector3(0, JumpForce));
}
}
}
Comment