using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public GameObject ArmaTopo;
public GameObject ArmaDir;
public GameObject ArmaBot;
public GameObject ArmaEsq;
public GameObject Projetil;
public static float forca = 1;
Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.W)) {
StartCoroutine (Fortificador ());
}
if (Input.GetKeyUp (KeyCode.W)){
rb.velocity = new Vector2 (0.0f, -forca);
forca = 1;
Atirar (ArmaTopo);
}
//Sobe
if (Input.GetKeyDown (KeyCode.S)) {
StartCoroutine (Fortificador ());
}
if (Input.GetKeyUp (KeyCode.S)){
rb.velocity = new Vector2 (0.0f, forca);
forca = 1;
Atirar (ArmaBot);
}
//Esquerda
if (Input.GetKeyDown (KeyCode.D)) {
StartCoroutine (Fortificador ());
}
if (Input.GetKeyUp (KeyCode.D)){
rb.velocity = new Vector2 (-forca, 0.0f);
forca = 1;
Atirar (ArmaDir);
}
//Direita
if (Input.GetKeyDown (KeyCode.A)) {
StartCoroutine (Fortificador ());
}
if (Input.GetKeyUp (KeyCode.A)){
rb.velocity = new Vector2 (forca, 0.0f);
forca = 1;
Atirar (ArmaEsq);
}
}
void Atirar(GameObject arma){
Instantiate (Projetil, arma.transform.position, arma.transform.rotation);
}
IEnumerator Fortificador(){
yield return new WaitForSeconds (0.1f);
if (Input.GetKey (KeyCode.W) || Input.GetKey (KeyCode.S) ||
Input.GetKey (KeyCode.A) || Input.GetKey (KeyCode.D)) {
forca++;
print (forca);
}
if (forca != 1) {
StartCoroutine (Fortificador ());
}
}
}
was correct?