//bool IsPlayerGrounded() //{ // return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1)); //} void Update() { if (Input.GetButtonDown("Jump") && isGrounded) { rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse); isGrounded = false; audio = GetComponent <AudioSource>(); audio.PlayOneShot(audio_jump); } float y = rb.position.y; if (y < -3) { //Destroy(gameObject); } if (Input.GetButtonDown("Potion") && potionPickedUp) { Debug.Log("Potion used!"); HealthWaterScript health = GetComponent <HealthWaterScript>(); if (health != null) { health.hp = health.maxHealth; health.healthBar.SetSize(1f); } potionPickedUp = false; } if (Input.GetButtonDown("Shield") && shieldPickedUp) { Debug.Log("Shield used!"); shieldActive = true; shieldDamageCounter = 3; shieldExpirationCounter = 10; shieldPickedUp = false; } if (shieldActive && shieldExpirationCounter == 0) { Debug.Log("Shield expired!"); shieldActive = false; shieldDamageCounter = 0; } }
IEnumerator Shoot() { audio_laser = GetComponent <AudioSource>(); audio_laser.Play(); RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.right); if (hitInfo) { Debug.Log(hitInfo.transform.name); EnemyWaterScript enemy = hitInfo.transform.GetComponent <EnemyWaterScript>(); ShotScript shot = hitInfo.transform.GetComponent <ShotScript>(); if (enemy != null) { HealthWaterScript health = hitInfo.transform.GetComponent <HealthWaterScript>(); if (health != null) { Debug.Log("DIE!!!!"); health.Damage(laserDmg); } } else if (shot != null) { Destroy(shot.gameObject); } lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hitInfo.point); } else { Debug.Log("No Hit!"); lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, firePoint.position + firePoint.right * 100); } lineRenderer.enabled = true; yield return(new WaitForSeconds(0.02f)); lineRenderer.enabled = false; }