// Update is called once per frame void Update() { if (Input.anyKeyDown && !Input.GetKey("c")) { // Check if the next key in the code is pressed if (Input.GetKeyDown(cheatCode[index])) { // Add 1 to index to check the next key in the code index++; } // Wrong key entered, we reset code typing else { index = 0; } } // If index reaches the length of the cheatCode string, // the entire code was correctly entered if (index == cheatCode.Length) { // Cheat code successfully inputted! // Unlock crazy cheat code stuff Animator anim = Barra.GetComponent <Animator>(); anim.runtimeAnimatorController = (RuntimeAnimatorController)Resources.Load("Animation/ShootStyle", typeof(RuntimeAnimatorController)); shootEnabled = true; tiempo = (float)0.05; StartCoroutine(Shoot()); index = 0; } if (Input.GetKey("space")) { MainBall.GetComponent <BallScript>().isInBarra = false; MainBall.GetComponent <BallScript>().velocidad = (float)0.1; } puntos.text = "Puntuacion: " + puntuacion; lifes.text = "Vidas: " + vidas; if (shootEnabled && !startShooting) { StartCoroutine(Shoot()); } if (ballAdded) { StartCoroutine(AddBall()); ballAdded = false; } if (MainBall == null) { GameObject flame = GameObject.FindGameObjectWithTag("Particulas"); if (flame != null) { Destroy(flame); } if (SecondaryBalls.Count != 0) { MainBall = SecondaryBalls[0]; SecondaryBalls.RemoveAt(0); } else { vidas--; Destroy(Barra); Barra = Instantiate(Resources.Load("Barra")) as GameObject; Barra.name = "Barra"; MainBall = Instantiate(Resources.Load("Ball")) as GameObject; MainBall.name = "Ball"; if (vidas == 0) { mapa1(); world = 1; vidas = 3; puntuacion = 0; } } } }
private IEnumerator AddBall() { Vector2 direccion = MainBall.GetComponent <BallScript>().direccion; //se calcula el angulo de 22.5 grados en radianes, ya que la bola se desplaza en un angulo de 45° float angulo = (float)(22.5 / 180 * Mathf.PI); // ahora la hipotenusa del triangulo formado por la direccion float h = Mathf.Sqrt(direccion.x * direccion.x + direccion.y * direccion.y); // se tiene a mano coseno y seno de 22.5° float cos = Mathf.Cos(angulo); float sen = Mathf.Sin(angulo); // se calcula h' que es la hipotenusa del triangulo de 22.5 float h2 = cos / h; // ahora falta calcular x e y para obtener las direcciones; float x = h2 * cos; float y = h2 * sen; // ahora tan solo falta ver a que cuadrante pertenece la direccion Vector2 dir1, dir2; // primer cuadrante if (direccion.x > 0 && direccion.y > 0) { dir1 = new Vector2(x, y); dir2 = new Vector2(y, x); } //segundo cuadrante else if (direccion.x < 0 && direccion.y > 0) { dir1 = new Vector2(-x, y); dir2 = new Vector2(-y, x); } // tercer cuadrante else if (direccion.x < 0 && direccion.y < 0) { dir1 = new Vector2(-x, -y); dir2 = new Vector2(-y, -x); } // cuarto cuadrante else { dir1 = new Vector2(x, -y); dir2 = new Vector2(y, -x); } Debug.Log(x); Debug.Log(y); GameObject Ball1 = Instantiate(Resources.Load("Ball")) as GameObject; GameObject Ball2 = Instantiate(Resources.Load("Ball")) as GameObject; SecondaryBalls.Add(Ball1); SecondaryBalls.Add(Ball2); yield return(new WaitForEndOfFrame()); Ball1.name = "Ball"; Ball1.GetComponent <BallScript>().direccion = dir1; Ball1.GetComponent <BallScript>().isInBarra = false; Ball1.transform.position = MainBall.transform.position; Ball1.GetComponent <BallScript>().velocidad = (float)0.1; Ball2.name = "Ball"; Ball2.GetComponent <BallScript>().direccion = dir2; Ball2.GetComponent <BallScript>().isInBarra = false; Ball2.transform.position = MainBall.transform.position; Ball2.GetComponent <BallScript>().velocidad = (float)0.1; }