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 System.Collections;
- public class player : MonoBehaviour {
- public float velocidade;
- public float direcao;
- public Rigidbody2D rb2D;
- public GameObject bala;
- public GameObject pontoBala;
- public bool podeAtirar = false;
- public float timer = 0;
- public GameObject bolinha;
- private Animator pAnimation;
- public bool ativaExplosao;
- private gameManager gmanagerScript;
- // Use this for initialization
- void Start () {
- pAnimation = GetComponent<Animator>();
- rb2D = GetComponent<Rigidbody2D>();
- ativaExplosao = false;
- gmanagerScript = GameObject.Find("GameManager").GetComponent<gameManager>();
- }
- // Update is called once per frame
- void Update () {
- direcao = Input.GetAxisRaw("Horizontal");
- if (gmanagerScript.vidas > 0)
- {
- if (podeAtirar == true && timer > 0)
- {
- if (Input.GetButtonDown("Fire4"))
- Instantiate(bala, pontoBala.transform.position, Quaternion.identity);
- timer -= Time.deltaTime;
- }
- }
- if (timer <= 0)
- podeAtirar = false;
- }
- void FixedUpdate()
- {
- if(gmanagerScript.vidas > 0)
- rb2D.velocity = new Vector2(direcao*velocidade, 0);
- }
- void OnTriggerEnter2D(Collider2D outro)
- {
- if (gmanagerScript.vidas > 0)
- {
- if (outro.gameObject.tag == "tamanho")
- {
- pAnimation.Play("aumenta_player");
- Destroy(outro.gameObject);
- }
- if (outro.gameObject.tag == "tiro")
- {
- if (podeAtirar == false)
- {
- timer = 10;
- podeAtirar = true;
- }
- Destroy(outro.gameObject);
- }
- if (outro.gameObject.tag == "fogo")
- {
- StartCoroutine(bolaFogo(10));
- Destroy(outro.gameObject);
- }
- }
- }
- void trocaAnim()
- {
- pAnimation.Play("parado");
- }
- IEnumerator bolaFogo(int tempoDeEspera)
- {
- ativaExplosao = true;
- Debug.Log("PEGOU FOGO!");
- yield return new WaitForSeconds(tempoDeEspera);
- ativaExplosao = false;
- Debug.Log("APAGOU O FOGO");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement