using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Fly : MonoBehaviour
{
Rigidbody2D physics;
[SerializeField]
private float force;
private Diretor diretor;
private Vector3 startPosition;
private void Awake()
{
this.startPosition = this.transform.position;
this.physics = this.GetComponent<Rigidbody2D>();
}
private void Start()
{
this.diretor = GameObject.FindObjectOfType<Diretor>();
}
public void Restart()
{
this.transform.position = this.startPosition;
this.physics.simulated = true;
}
// Essa opção me permite ao clica no botão space do teclado dar um impulso no objeto, porém gostaria de poder controlalo livrimente no ar!
private void Update()
{
if (Input.GetButtonDown("Jump"))
{
this.Boost();
}
}
private void Boost()
{
this.physics.velocity = Vector2.zero;
this.physics.AddForce(Vector2.up * this.force, ForceMode2D.Impulse);
}
private void OnCollisionEnter2D(Collision2D collision)
{
this.physics.simulated = false;
this.diretor.EndGame();
}
}