private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Enemy" || collision.tag == "Scene") { Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius); foreach (Collider2D collider in colliders) { if (collider.tag == "Enemy" && collider.name != "weapon") { EnemyEventHandler enemy = collider.GetComponentInParent <EnemyEventHandler>(); EffectHandler.Instance.PlaySound(transform.position, SoundType.Hurt); EffectHandler.Instance.InstantiateParticleWithRotation(transform.position, ParticleType.EnemyBlood, color: enemy.mainColor); enemy.Damage(damage); } } Destroy(gameObject); } }
private void OnTriggerEnter2D(Collider2D collision) { if (type == BulletType.Player) { if (collision.tag != "Player") { if (collision.tag == "Enemy") { EnemyEventHandler enemy = collision.GetComponentInParent <EnemyEventHandler>(); EffectHandler.Instance.PlaySound(transform.position, SoundType.Hurt); EffectHandler.Instance.InstantiateParticleWithRotation(transform.position, ParticleType.EnemyBlood, color: enemy.mainColor); enemy.Damage(damage); Destroy(gameObject); } else if (collision.tag == "Scene") { EffectHandler.Instance.PlaySound(transform.position, SoundType.Hit); EffectHandler.Instance.InstantiateParticleWithRotation(transform.position, ParticleType.WallPlayer); Destroy(gameObject); } } } else if (type == BulletType.Enemy) { if (collision.tag != "Enemy") { if (collision.tag == "Player") { EffectHandler.Instance.PlaySound(transform.position, SoundType.Hurt); EffectHandler.Instance.InstantiateParticleWithRotation(transform.position, ParticleType.PlayerBlood); collision.GetComponent <PlayerController>().Damage(damage); Destroy(gameObject); } else if (collision.tag == "Scene") { EffectHandler.Instance.PlaySound(transform.position, SoundType.Hit); EffectHandler.Instance.InstantiateParticleWithRotation(transform.position, ParticleType.WallEnemy); //TilemapManager.Instance.GetTilemap(0).DamageTile(Vector3Int.CeilToInt(transform.position) - Vector3.one, 0.35f); Destroy(gameObject); } } } }
private void ShootRay() { Vector3 direction = (cam.ScreenToWorldPoint(Input.mousePosition) - bulletSpawnPos.position).normalized; RaycastHit2D hit = Physics2D.Raycast(bulletSpawnPos.position, direction, Mathf.Infinity, shootingRayLayerMask); if (hit.collider != null) { if (hit.collider.tag == "Enemy") { EnemyEventHandler enemy = hit.collider.GetComponentInParent <EnemyEventHandler>(); enemy.Damage(weapon.damage); EffectHandler.Instance.PlaySound(hit.point, SoundType.Hurt); EffectHandler.Instance.InstantiateParticleWithRotation(hit.point, ParticleType.EnemyBlood, color: enemy.mainColor, moveRight: false); } else { EffectHandler.Instance.PlaySound(hit.point, SoundType.Hit); EffectHandler.Instance.InstantiateParticleWithRotation(hit.point, ParticleType.WallPlayer, moveRight: false); } StartCoroutine(DrawLine(hit.point)); } }