Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////
- // Créditos Équilibré Cursos e Treinamentos //
- // http://www.equilibrecursos.net //
- // http://www.youtube.com/equilibrecursos //
- //////////////////////////////////////////////
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class bola : MonoBehaviour {
- public float velBola;
- public Transform jogador;
- public Rigidbody2D rb2D;
- public float posicaoBolinha;
- private bool comecou;
- public GameObject[] powerUps;
- public float porcentagem;
- private player scriptPlayer;
- public GameObject explosao;
- private gameManager gManagerScript;
- public Image goverImage;
- // Use this for initialization
- void Start () {
- //rigidbody2D.velocity = new Vector2(Random.Range(-2, 2), velBola);
- gManagerScript = GameObject.Find("GameManager").GetComponent<gameManager>();
- scriptPlayer = GameObject.Find("player").GetComponent<player>();
- rb2D = GetComponent<Rigidbody2D>();
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space) && !comecou)
- {
- rb2D.velocity = new Vector2(Random.Range(-2f, 2f), velBola);
- comecou = true;
- }
- if (!comecou)
- {
- transform.position = new Vector2(jogador.position.x, transform.position.y);
- }
- }
- void FixedUpdate () {
- if (comecou)
- {
- if (rb2D.velocity.y < 2 && GetComponent<Rigidbody2D>().velocity.y > -2)
- {
- rb2D.gravityScale = 3;
- }
- else
- {
- rb2D.gravityScale = 0;
- }
- }
- }
- float colisaoBolinha (Vector2 posicaoBolinha, Vector2 posicaoJogador, float larguraJogador)
- {
- return (posicaoBolinha.x - posicaoJogador.x) / larguraJogador;
- }
- void OnCollisionEnter2D(Collision2D outro)
- {
- if (outro.gameObject.tag == "bloco_verde" || outro.gameObject.tag == "bloco_laranja" || outro.gameObject.tag == "bloco_azul" || outro.gameObject.tag == "bloco_amarelo")
- {
- if (scriptPlayer.ativaExplosao)
- Instantiate(explosao, outro.transform.position, Quaternion.identity);
- if (Random.Range(0f, 1f) <= porcentagem)
- {
- Instantiate(powerUps[Random.Range(0,powerUps.Length)], outro.gameObject.transform.position, Quaternion.identity);
- }
- Destroy(outro.gameObject);
- }
- if (outro.gameObject.tag == "Player")
- {
- float resultadoCalculo = colisaoBolinha(transform.position, outro.transform.position, ((BoxCollider2D)outro.collider).size.x);
- Vector2 novaDirecao = new Vector2(resultadoCalculo, 1).normalized;
- rb2D.velocity = novaDirecao * velBola;
- }
- if (outro.gameObject.tag == "colisorBaixo")
- {
- if (gManagerScript.vidas > 1)
- {
- gManagerScript.vidas -= 1;
- transform.position = new Vector2(jogador.position.x, jogador.position.y + posicaoBolinha);
- comecou = false;
- rb2D.velocity = Vector2.zero;
- } else
- {
- goverImage.enabled = true;
- gManagerScript.vidas -= 1;
- Destroy(gameObject);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement