Here is my code so far
private Rigidbody2D rB;
private Vector2 mousePos;
private float speed = -10.0f;
private bool canSlow;
// Start is called before the first frame update
void Start()
{
rB = GetComponent<Rigidbody2D>();
canSlow = false;
}
// Update is called once per frame
void Update()
{
if (canSlow)
{
speed += 0.1f;
}
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (Input.GetMouseButton(0)) // If pressing the mouse
{
Vector2 lookDir = mousePos - rB.position;
float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
rB.rotation = angle;
}
if (Input.GetMouseButtonUp(0)) // If let up the mouse
{
canSlow = true;
rB.AddForce(transform.up * speed * Time.deltaTime, ForceMode2D.Impulse);
}
}