Robot Kyle keeps moving left

I have done the basic tutorial. Everything worked out fine except one thing. I have one problem and that is that Robot Kyle some times keeps moving to the left constantly. I use two screens. when i press on something on my other screen Kyle stops running, but when i'm selecting the game again, Kyle starts running to the left again. Kyle will react to the other keys as well like jumping. This does not always happen.

My animator script;

public class PlayerAnimatorManager : MonoBehaviourPun
{
#region PUBLIC PROPERTIES

public float DirectionDampTime = 0.25f;

#endregion

#region PRIVATE PROPERTIES

Animator animator;

#endregion

#region MONOBEHAVIOUR MESSAGES

/// <summary>
/// MonoBehaviour method called on GameObject by Unity during initialization phase.
/// </summary>
void Start()
{
animator = GetComponent<Animator>();
}

/// <summary>
/// MonoBehaviour method called on GameObject by Unity on every frame.
/// </summary>
void Update()
{

// Prevent control is connected to Photon and represent the localPlayer
if (photonView.IsMine == false && PhotonNetwork.IsConnected == true)
{
return;
}

// failSafe is missing Animator component on GameObject
if (!animator)
{
return;
}

// deal with Jumping
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);

// only allow jumping if we are running.
if (stateInfo.IsName("Base Layer.Run"))
{
// When using trigger parameter
if (Input.GetButtonDown("Fire2")) animator.SetTrigger("Jump");
}

// deal with movement
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");

// prevent negative Speed.
if (v < 0)
{
v = 0;
}

// set the Animator Parameters
animator.SetFloat("Speed", h * h + v * v);
animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
}

#endregion
}

Comments

  • Arie
    Arie
    edited July 30
    It looks like it only happens when you press play "fast" after you open the application or when it starts well, but i press on something on my other screen and than come back to the app.
  • Sorry, apparently it had something to do with my computer..