69 lines
No EOL
1.6 KiB
C#
69 lines
No EOL
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PlayerController : MonoBehaviour
|
|
{
|
|
public enum PickupType
|
|
{
|
|
PizzaPickup = 1
|
|
};
|
|
|
|
public Rigidbody2D player;
|
|
public float speed = 10f;
|
|
public float runMultiplier = 1.5f;
|
|
public Text movementType;
|
|
|
|
public Text pizzaCountDisplay;
|
|
private int _pizzaCount = 0;
|
|
|
|
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;
|
|
}
|
|
|
|
private void OnCollisionEnter2D(Collision2D other)
|
|
{
|
|
Debug.Log(other.gameObject.tag);
|
|
if (other.gameObject.tag.Equals("Pickup"))
|
|
{
|
|
Destroy(other.gameObject);
|
|
GivePickup(other.gameObject.GetComponent<PickupBounce>().type);
|
|
}
|
|
}
|
|
|
|
private void GivePickup(PickupType type)
|
|
{
|
|
Debug.Log(type.ToString());
|
|
switch (type)
|
|
{
|
|
case PickupType.PizzaPickup:
|
|
_pizzaCount++;
|
|
pizzaCountDisplay.text = $"Pizza Count: {_pizzaCount.ToString()}";
|
|
break;
|
|
default:
|
|
Debug.LogWarning($"Unrecognised PickupType: {type.ToString()}");
|
|
break;
|
|
}
|
|
}
|
|
} |