When I test my game with two players they both move with the same input. What do I need to correct in my Player Controller script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityStandardAssets.CrossPlatformInput;
public class MultiplayerController : NetworkBehaviour
{
public float moveSpeed;
private float currentMoveSpeed;
private Animator anim;
private Rigidbody2D myRigidbody;
private bool playerMoving;
public Vector2 lastMove;
private Vector2 moveCrossPlatformInputManager;
private static bool playerExists;
public string startPoint;
// Use this for initialization
void Start()
{
anim = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
if (!isLocalPlayer)
return;
playerMoving = false;
moveCrossPlatformInputManager = new Vector2(CrossPlatformInputManager.GetAxisRaw("Horizontal"), CrossPlatformInputManager.GetAxisRaw("Vertical")).normalized;
if (moveCrossPlatformInputManager != Vector2.zero)
{
myRigidbody.velocity = new Vector2(moveCrossPlatformInputManager.x * moveSpeed, moveCrossPlatformInputManager.y * moveSpeed);
playerMoving = true;
lastMove = moveCrossPlatformInputManager;
}
else {
myRigidbody.velocity = Vector2.zero;
}
anim.SetFloat("MoveX", CrossPlatformInputManager.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", CrossPlatformInputManager.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
}
}