private void OnTriggerStay(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("Default")) { Espuma padre = GetComponentInParent <Espuma>(); if (padre != null) { Destroy(padre.gameObject); } } }
void Update() { if (healt <= 0 || Partida.partida.endLevel) { disponibilidadActual = Mathf.Max(disponibilidadActual - 1, 0); if (healt <= 0) { light.range *= 0.99f; } return; } Vector3 moveDirection = Vector3.zero; if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { moveDirection.y += 1f; } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { moveDirection.y -= 1f; } if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { moveDirection.x -= 1f; } if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { moveDirection.x += 1f; } if (Time.time > stopTime) { if (moveDirection == Vector3.zero) { anim = "idle"; } else { anim = "walk"; if (Mathf.Abs(moveDirection.x) > 0.5f) { horizontalAnim = moveDirection.x > 0f ? "right" : "left"; } else { horizontalAnim = ""; } if (Mathf.Abs(moveDirection.y) > 0.5f) { verticalAnim = moveDirection.y > 0f ? "up" : "down"; } else { verticalAnim = ""; } moveDirection = moveDirection.normalized; } rb.velocity = moveDirection * velocity; } animation.setBlinking(Time.time - lastBlinking < blinkingDuration); animation.beginAnimation(anim + horizontalAnim + verticalAnim); if (Input.GetKey(KeyCode.Space)) { if (Time.time - lastReload > reloadTime && disponibilidadActual < maximaDisponibilidadArma) { lastReload = Time.time; Espuma espuma = Instantiate(espumaPrefab, transform).GetComponent <Espuma>(); espuma.Salir(transform.position, getViewDirection(), espumaLevel); disponibilidadActual++; } } else { if (Time.time - lastReload > reloadTime) { lastReload = Time.time; getViewDirection(); disponibilidadActual = Mathf.Max(disponibilidadActual - 1, 0); } } RenderSettings.ambientLight = new Color(1 - darkness, 1 - darkness, 1 - darkness); light.range = lightRadius; }