private void Awake() { imagen2 = imagen; muertescript = canvas.GetComponent <Muerte>(); Debug.Log(muertescript); gamecontroller = this; if (posiciondelarma.GetComponentInChildren <ControladorArma>() != null) { arma = posiciondelarma.GetComponentInChildren <ControladorArma>(); } }
// Update is called once per frame private void Update() { if (imagen2.active == true) { this.transform.GetChild(0).parent = null; this.enabled = false; } //Si pulsas el botón de disparar, disparas una bala if (puedeDisparar && Input.GetMouseButtonDown(0)) { StopCoroutine(TiempoEspera(.03f)); StartCoroutine(TiempoEspera(.03f)); if (arma != null) { arma.Disparar(Camera.main.transform.position + (Camera.main.transform.forward * .5f) + (Camera.main.transform.up * -.02f), Camera.main.transform.rotation, false, null); } } //Si pulsas el otro botón tiras el arma if (Input.GetMouseButtonDown(1) && (!arma.recargando || arma == null)) { StopCoroutine(TiempoEspera(.4f)); StartCoroutine(TiempoEspera(.4f)); if (arma != null) { arma.Lanzar(); arma = null; } } //Si no tienes arma, pero tu vista está sobre un arma, y pulsas el botón de disparar, el alma volará hacia ti RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 10, capa) && Input.GetMouseButtonDown(0) && arma == null) { hit.transform.GetComponent <ControladorArma>().Recoger(); } float x = Input.GetAxisRaw("Horizontal"); float y = Input.GetAxisRaw("Vertical"); float tiempo = (x != 0 || y != 0) ? 1f : .03f; float lerpTime = (x != 0 || y != 0) ? .05f : .5f; tiempo = accion ? 1 : tiempo; lerpTime = accion ? .1f : lerpTime; //Escala el tiempo segun tu movimiento, si te mueves el tiempo se vuelve normal, si no, mas lento Time.timeScale = Mathf.Lerp(Time.timeScale, tiempo, lerpTime); }
/// <summary> /// Se cae al suelo como si estuviese muerto /// </summary> public void Muerte() { animacion.enabled = false; Rotura[] partes = GetComponentsInChildren <Rotura>(); foreach (Rotura rotura in partes) { rotura.rigibody.isKinematic = false; rotura.rigibody.interpolation = RigidbodyInterpolation.Interpolate; } muerto = true; if (posicionarma.GetComponentInChildren <ControladorArma>() != null) { ControladorArma arma = posicionarma.GetComponentInChildren <ControladorArma>(); arma.Soltar(); } }