// Update is called once per frame void Update() { if (central.estado == Central.EstadoJuego.Pausa && estado != EstadoZanahoria.enDisparo) { return; } switch (estado) { case Zanahoria.EstadoZanahoria.enPlaneta: transform.position = punto.position; transform.rotation = punto.rotation; if (Input.GetButtonDown("Fire1")) { estado = EstadoZanahoria.preparando; cargando.Play(); cargandoAudio.Play(); animator.SetBool("cargando", true); //barraCarga.transform.parent.localPosition = new Vector3(Camera.main.WorldToScreenPoint(transform.position).x + 50f, Camera.main.WorldToScreenPoint(transform.position).y + 75f, 0f); barraCarga.transform.parent.localPosition = Input.mousePosition - new Vector3(Screen.width / 2f, Screen.height / 2f, 0f); barraCarga.transform.parent.gameObject.SendMessage("PlayForward"); barraCarga.fillAmount = 0f; } break; case EstadoZanahoria.preparando: transform.position = punto.position; transform.rotation = punto.rotation; if (Input.GetButton("Fire1")) { fuerzaCarga += 1000f * Time.deltaTime; if (fuerzaCarga > fuerzaCargaMaximo) { fuerzaCarga = fuerzaCargaMaximo; disparar(); } barraCarga.fillAmount = (fuerzaCarga / fuerzaCargaMaximo); //print (Input.mousePosition.x + " " + Input.mousePosition.y); //barraCarga.transform.parent.localPosition = new Vector3(Camera.main.WorldToScreenPoint(transform.position).x + 0f, Camera.main.WorldToScreenPoint(transform.position).y + 0f, 0f) * altoSugerido / Screen.height;//Input.mousePosition.x + 50f, Input.mousePosition.y + 75f, 0f); } if (Input.GetButtonUp("Fire1")) { disparar(); } break; case EstadoZanahoria.enDisparo: //print(rigidbody.velocity.magnitude); if (transform.eulerAngles.z < 0f || transform.eulerAngles.z > 180f) { motorAudio.pitch = 0.3f; humo.Stop(); } else { motorAudio.pitch = rigidbody.velocity.magnitude / 40f; } if (tiempoConejoGrito < Time.time) { conejoGritar(); } Vector3 fuerzaGravedad = Vector3.zero; foreach (Planeta p in planetas) { float distancia = Vector3.Distance(p.transform.position, transform.position); if (distancia <= p.distanciaEfecto && !p.aterrizado) { fuerzaGravedad += ((p.transform.position - transform.position) / distancia) * p.gravedad; } } rigidbody.AddForce(new Vector2(fuerzaGravedad.x, fuerzaGravedad.y) * Time.deltaTime); transform.right = rigidbody.velocity.normalized; if (transform.position.y < -40f) { barraCarga.transform.parent.gameObject.SendMessage("PlayReverse"); estado = EstadoZanahoria.enHoyoNegro; rigidbody.isKinematic = true; central.resumenJuego(contadorPlanetas, nConejos); motorAudio.Stop(); } break; } //barraCarga.transform.parent.localPosition = new Vector3(Camera.main.WorldToScreenPoint(transform.position).x + 0f, Camera.main.WorldToScreenPoint(transform.position).y + 0f, 0f) * altoSugerido / Screen.height;//Input.mousePosition.x + 50f, Input.mousePosition.y + 75f, 0f); }