Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using UnityEngine.UI;
- public class BeeController : MonoBehaviour
- {
- Rigidbody2D rig;
- public int health; // vida do player
- public TMP_Text txt_health;
- public float speed; // velocidade do player
- // PowerUps
- public GameObject pwUp_HUD; // Hud do PowerUp
- public Slider pwUp_slider_duracao; // Duração do PowerUp
- public TMP_Text pwUp_txt_nome;
- public bool onPowerUp; // PowerUp ativo
- public float pwUp_duracao; // Duração do PowerUp
- public bool escudo; // Escudo para abelha
- void Start()
- {
- rig = this.GetComponent<Rigidbody2D>();
- }
- void Update()
- {
- txt_health.text = health.ToString();
- Move();
- if(onPowerUp)
- {
- pwUp_slider_duracao.value -= Time.deltaTime;
- }
- }
- void FixedUpdate()
- {
- rig.velocity = new Vector2(speed, rig.velocity.y);
- }
- //SISTEMA DE DANO;
- //FUTURAMENTE, MELHORAR ESSE SISTEMA
- public void OnHit(int dmg)
- {
- if(!escudo)
- {
- health -= dmg;
- }
- else
- {
- dmg = 0;
- }
- if(health <= 0)
- {
- GameController.instance.ShowGameOver();
- }
- }
- // CONTROLE DE MOVIMENTAÇÃO DA BEEZU
- void Move()
- {
- if(Input.GetAxis("Vertical") != 0)
- {
- rig.velocity = new Vector2(0, Input.GetAxis("Vertical") * speed);
- }
- else
- {
- rig.velocity = Vector2.zero;
- }
- }
- // Método de PowerUp de Velocidade
- public IEnumerator PowerUpVelocidade(float duracao)
- {
- pwUp_slider_duracao.maxValue = duracao;
- pwUp_slider_duracao.value = duracao;
- pwUp_duracao = duracao;
- pwUp_HUD.SetActive(true); // Ativa o HUD
- onPowerUp = true; // Ativa o pwUp
- pwUp_txt_nome.text = "Velocidade x2";
- float temp = speed;
- speed = speed * 2; // Velocidade multiplicado por 2
- yield return new WaitForSeconds(pwUp_duracao); // Duração do pwUp
- speed = temp;
- onPowerUp = false; // Desativa o pwUp
- pwUp_HUD.SetActive(false); // Desativa o HUD
- }
- public IEnumerator PowerUpEscudo(float duracao)
- {
- pwUp_slider_duracao.maxValue = duracao;
- pwUp_slider_duracao.value = duracao;
- pwUp_duracao = duracao;
- pwUp_HUD.SetActive(true); // Ativa o HUD
- onPowerUp = true; // Ativa o pwUp
- pwUp_txt_nome.text = "Invulnerável";
- escudo = true; // Ativa o Escudo
- yield return new WaitForSeconds(pwUp_duracao); // Duração do pwUp
- escudo = false; // Desativa o escudo
- onPowerUp = false; // Desativa o pwUp
- pwUp_HUD.SetActive(false); // Desativa o HUD
- }
- //Método de colisão com os coletáveis
- void OnTriggerEnter2D(Collider2D col)
- {
- if(col.gameObject.tag == "Coletavel") // Passar de fase
- {
- GameController.instance.Coletou();
- Destroy(col.gameObject);
- }
- if(col.gameObject.tag == "pwUp_velocidade") // Aumenta a velocidade
- {
- Destroy(col.gameObject);
- StartCoroutine(PowerUpVelocidade(5f));
- }
- if(col.gameObject.tag == "pwUp_escudo") // Deixa Invulnerável
- {
- Destroy(col.gameObject);
- StartCoroutine(PowerUpEscudo(5f));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement