1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-23 01:44:18 +00:00
keep-everything-alive/Assets/Scripts/Microgame_YourShip/PlayerMovement.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2020-04-19 14:24:38 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
private Rigidbody2D rb;
public GameObject hull;
public float horizontalShipSpeed = 5f;
public float verticalShipSpeed = 30;
public float maxJetFuel = 2f;
public float jetFuelRechargeSpeed = 0.1f;
private float jetFuel;
void Start () {
rb = GetComponent<Rigidbody2D>();
jetFuel = maxJetFuel;
}
void FixedUpdate () {
if (Input.GetAxis("Horizontal") < 0)
{
hull.transform.localScale = new Vector3(-1, 1, 1);
rb.AddForce(Vector2.right * -horizontalShipSpeed);
}
if (Input.GetAxis("Horizontal") > 0)
{
hull.transform.localScale = new Vector3(1, 1, 1);
rb.AddForce(Vector2.right * horizontalShipSpeed);
}
if (Input.GetAxis("Vertical") > 0)
{
if (jetFuel > 0f)
{
jetFuel = Mathf.Clamp(jetFuel - Time.deltaTime, 0, maxJetFuel);
rb.AddForce(Vector2.up * verticalShipSpeed);
}
}
else
{
jetFuel = Mathf.Clamp(jetFuel + Time.deltaTime, 0, maxJetFuel);
}
}
}