Advertisement
gizoncio

Breakout aula 18 - player.cs

Sep 6th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. //////////////////////////////////////////////
  2. // Créditos Équilibré Cursos e Treinamentos //
  3. // http://www.equilibrecursos.net           //
  4. // http://www.youtube.com/equilibrecursos   //
  5. //////////////////////////////////////////////
  6.  
  7. using UnityEngine;
  8. using System.Collections;
  9.  
  10. public class player : MonoBehaviour {
  11.  
  12.     public float velocidade;
  13.     public float direcao;
  14.     public Rigidbody2D rb2D;
  15.     public GameObject bala;
  16.     public GameObject pontoBala;
  17.     public bool podeAtirar = false;
  18.     public float timer = 0;
  19.  
  20.     public GameObject bolinha;
  21.  
  22.     private Animator pAnimation;
  23.  
  24.     public bool ativaExplosao;
  25.  
  26.     private gameManager gmanagerScript;
  27.  
  28.     // Use this for initialization
  29.     void Start () {
  30.         pAnimation = GetComponent<Animator>();
  31.         rb2D = GetComponent<Rigidbody2D>();
  32.         ativaExplosao = false;
  33.         gmanagerScript = GameObject.Find("GameManager").GetComponent<gameManager>();
  34.     }
  35.    
  36.     // Update is called once per frame
  37.     void Update () {
  38.         direcao = Input.GetAxisRaw("Horizontal");
  39.  
  40.         if (gmanagerScript.vidas > 0)
  41.         {
  42.             if (podeAtirar == true && timer > 0)
  43.             {
  44.                 if (Input.GetButtonDown("Fire4"))
  45.                     Instantiate(bala, pontoBala.transform.position, Quaternion.identity);
  46.  
  47.                 timer -= Time.deltaTime;
  48.             }
  49.         }
  50.  
  51.         if (timer <= 0)
  52.             podeAtirar = false;
  53.     }
  54.  
  55.     void FixedUpdate()
  56.     {
  57.         if(gmanagerScript.vidas > 0)
  58.             rb2D.velocity = new Vector2(direcao*velocidade, 0);
  59.     }
  60.  
  61.     void OnTriggerEnter2D(Collider2D outro)
  62.     {
  63.         if (gmanagerScript.vidas > 0)
  64.         {
  65.             if (outro.gameObject.tag == "tamanho")
  66.             {
  67.                 pAnimation.Play("aumenta_player");
  68.                 Destroy(outro.gameObject);
  69.             }
  70.  
  71.             if (outro.gameObject.tag == "tiro")
  72.             {
  73.                 if (podeAtirar == false)
  74.                 {
  75.                     timer = 10;
  76.                     podeAtirar = true;
  77.                 }
  78.                 Destroy(outro.gameObject);
  79.             }
  80.  
  81.             if (outro.gameObject.tag == "fogo")
  82.             {
  83.                 StartCoroutine(bolaFogo(10));
  84.  
  85.                 Destroy(outro.gameObject);
  86.             }
  87.         }
  88.     }
  89.  
  90.     void trocaAnim()
  91.     {
  92.         pAnimation.Play("parado");
  93.     }
  94.  
  95.     IEnumerator bolaFogo(int tempoDeEspera)
  96.     {
  97.  
  98.         ativaExplosao = true;
  99.         Debug.Log("PEGOU FOGO!");
  100.  
  101.         yield return new WaitForSeconds(tempoDeEspera);
  102.  
  103.         ativaExplosao = false;
  104.         Debug.Log("APAGOU O FOGO");
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement