void Shoot() { timer = 0f; if (!ASFire.isPlaying) { ASFire.Play(); } Particles.Stop(); Particles.Play(); LineFireFX.SetActive(true); Vector2 origen = new Vector2(SpawnBullets.position.x, SpawnBullets.position.y); Vector3 dir = SpawnBullets.right; Vector2 direccion = new Vector2(dir.x, dir.y); RaycastHit2D shootHit = Physics2D.Raycast(origen, direccion, range); if (shootHit.collider != null) { PlayerHealth2D playerHealth = shootHit.collider.GetComponent <PlayerHealth2D> (); if (playerHealth != null) { playerHealth.TakeDamage(damagePerShot); } } }
void Explision() { Instantiate(ParticleExplosion, transform.position, Quaternion.identity); Vector2 explosionPos = transform.position; Collider2D[] colliders = Physics2D.OverlapCircleAll(explosionPos, radiusExplosion); foreach (Collider2D hit in colliders) { if (hit.isTrigger || hit.tag == "Grenade") { continue; } Rigidbody2D rb = hit.GetComponent <Rigidbody2D> (); EnemyHealth enemyHealth = hit.GetComponent <EnemyHealth> (); //shootHit.collider.GetComponent <EnemyHealth> (); PlayerHealth2D playerHealth = hit.GetComponent <PlayerHealth2D>(); if (rb != null) { rb.AddForce(hit.transform.right * powerExplosion); } if (enemyHealth != null) { enemyHealth.TakeDamage(damagePerShot); } if (playerHealth != null) { playerHealth.TakeDamage(damagePerShot); } SRGrenade.sprite = null; AudioSourceExplosion.Play(); } Destroy(gameObject); this.enabled = false; }