using UnityEngine;
using Photon.Pun;

public class PlayerInputProvider : MonoBehaviourPunCallbacks
{

    [SerializeField]
    private KartController kart = null;

    private void Update()
    {
		if (photonView && !photonView.IsMine && PhotonNetwork.IsConnected) {
			return;
		}

        if (kart == null)
        {
            return;
        }

        // ZAS: If we are accelerating, tell the kart to accelerate
		if (Input.GetMouseButton (0) || Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
			if (kart) {
				kart.Accelerate(true);
			}
		}

		if (Input.GetMouseButton (1) || Input.GetKey(KeyCode.Space)) {
			if (kart) {
				kart.Jump ();
			}
		}

		// ZAS: If we are accelerating, tell the kart to accelerate
		if (!Input.GetMouseButton (0) && Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) {
			if (kart) {
				kart.Accelerate(false);
			}
		}

        // ZAS: Tell the kart how to steer each update
        float horizontalMovement = Input.GetAxis("Horizontal");
		if (kart) {
			kart.Steer(horizontalMovement);
		}
    }

}
