public void LoseHealth(int healthDelta) { m_currentHealth -= healthDelta; GameObject particle = Instantiate(bloodParticle, transform.position, transform.rotation) as GameObject; Destroy(particle, 1f); if (!m_PlayAudio.isPlaying()) { m_PlayAudio.PlayClip(HurtSound); } if (m_currentHealth <= 0) { Destroy(this.gameObject); if (remainsPrefab != null) { if (!remains) { remains = Instantiate(remainsPrefab, this.transform.position, Quaternion.identity); } Destroy(remains, remainsDuration); } } }
private IEnumerator MoveSound() { playingSound = true; m_PlayAudio.PlayClip(MoveClip); yield return(new WaitForSeconds(0.3f)); playingSound = false; }
private void GroundCheck() { RaycastHit2D[] collisions = new RaycastHit2D[3]; Vector2 middleOrigin = new Vector2(m_Transform.position.x + offset.x, m_Transform.position.y + offset.y); Vector2 leftOrigin = new Vector2(middleOrigin.x - (objectWidth / 2), middleOrigin.y); Vector2 rightOrigin = new Vector2(middleOrigin.x + (objectWidth / 2), middleOrigin.y); collisions[0] = Physics2D.Raycast(middleOrigin, Vector2.down, raycastLength, mask); collisions[1] = Physics2D.Raycast(leftOrigin, Vector2.down, raycastLength, mask); collisions[2] = Physics2D.Raycast(rightOrigin, Vector2.down, raycastLength, mask); foreach (RaycastHit2D hit in collisions) { if (hit && (hit.collider.CompareTag("Ground") || hit.collider.CompareTag("Floor"))) { m_RemainingJumps = maxJumps; m_IsGrounded = true; m_PlayAudio.PlayClip(LandClip); } } /* * Vector2 middleOrigin = new Vector2(m_Transform.position.x + offset.x, m_Transform.position.y + offset.y); * RaycastHit2D hit = Physics2D.Raycast(middleOrigin, Vector2.down, raycastLength); * * if (hit && hit.collider.CompareTag("Ground")) * { * print(hit.collider.gameObject.name); * m_RemainingJumps = maxJumps; * m_IsGrounded = true; * } * else * { * m_IsGrounded = false; * if (m_RemainingJumps == maxJumps) * --m_RemainingJumps; * } */ if (debug) { Debug.DrawRay(middleOrigin, Vector3.down * raycastLength, Color.blue, 1); Debug.DrawRay(leftOrigin, Vector3.down * raycastLength, Color.blue, 1); Debug.DrawRay(rightOrigin, Vector3.down * raycastLength, Color.blue, 1); } }
public void Shoot() { Vector3 playerPos = player.position; Vector3 dir = new Vector3(playerPos.x - m_Transform.position.x, playerPos.y - m_Transform.position.y, 0); if (!isFacing()) { return; } //Debug.Log($"{v.normalized} {v}"); Vector3 spawnPosition = m_Transform.position + dir.normalized; m_PlayAudio.PlayClip(ShootClip); GameObject newProjectile = Instantiate(projectileType, spawnPosition, Quaternion.identity) as GameObject; newProjectile.GetComponent <EnemyProjectile>().m_Direction = dir.normalized; }
public void Shoot() { if (m_CanShoot && !paused) { if (projectileType.name.Contains("Pepper")) { offset.y = pepperOffset[pepperOffsetIndex]; lastIndex = pepperOffsetIndex; } Vector3 spawnOffset = (m_Transform.right * offset.x) + (m_Transform.up * offset.y) + (m_Transform.forward * offset.z); Vector3 spawnPosition = new Vector3(m_Transform.position.x + spawnOffset.x, m_Transform.position.y + spawnOffset.y, m_Transform.position.z + spawnOffset.z); Instantiate(projectileType, spawnPosition, m_Transform.rotation); if (ShootSound != null) { m_PlayAudio.PlayClip(ShootSound); } if (projectileType.name.Contains("Pepper")) { /*pepperOffsetIndex++; * if (pepperOffsetIndex >= pepperOffset.Count) * { * pepperOffsetIndex = 0; * }*/ if (pepperOffsetIndex == lastIndex) { pepperOffsetIndex = Random.Range(0, pepperOffset.Count); } } StartCoroutine(Cooldown()); } }
public void LoseHealth(int healthDelta) { if (isDamagable && !dead) { m_CurrentHealth -= healthDelta; m_PlayAudio.PlayClip(HurtSound); if (m_CurrentHealth > 0) { StartCoroutine("Blink"); GameObject particle = Instantiate(bloodParticle, transform.position, transform.rotation) as GameObject; Destroy(particle, 1f); } else { dead = true; RagDoll(); // StartCoroutine(Die()); } } // Do something when we die/get hit by something. }