Devtober-Apocalypse-2019/Assets/Scripts/PlayerController.cs

35 lines
No EOL
796 B
C#

using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public Rigidbody2D player;
public float speed = 10f;
public float runMultiplier = 1.5f;
public Text movementType;
private void Start()
{
movementType.text = "Walking";
}
private void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector2 movement = new Vector2(moveHorizontal, moveVertical);
if (Input.GetKey("left shift"))
{
movement *= runMultiplier;
movementType.text = "Running";
}
else
{
movementType.text = "Walking";
}
player.velocity = movement * speed;
}
}