// Shooting towards target position private void ShootAtPlayer() { EnemyBullet bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody2D>().velocity = TargetDirection() * bulletSpeed; }
/// <summary> /// Boss shooting behaviour implmementation. /// </summary> private void BossShooting() { var target = TargetDirection(); EnemyBullet bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody2D>().velocity = target * bulletSpeed * 2f; bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody2D>().velocity = new Vector2(target.x + 0.2f, target.y) * bulletSpeed * 1.5f; bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.GetComponent <Rigidbody2D>().velocity = new Vector2(target.x - 0.2f, TargetDirection().y) * bulletSpeed * 1.5f; }
// Straight down shot private void ShootStraightDown() { EnemyBullet bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; Rigidbody2D rb = bullet.GetComponent <Rigidbody2D>(); rb.velocity = Vector2.down * bulletSpeed; }
/// <summary> /// 총알을 발사하고 /// 설정한다. /// </summary> void FireBullet() { EnemyBullet bullet = GameObject.Instantiate <EnemyBullet>(); Vec2D bulletPoint = gameObject.transform.position; bulletPoint.Y += 8; bullet.transform.position = bulletPoint; DamageSystem damageSystem = bullet.GetComponent <DamageSystem>(); damageSystem.EventGiveDamage += () => GameObject.Destroy(bullet); }
void OnHit(PlayerAttack hit) { // The DV boss has a chance to deflect normal and shotgun bullets if ((hit is Bullet1 || hit is Bullet3) && GetComponent <DVBoss>() != null) { float chance = UnityEngine.Random.value; if (chance <= 0.2f) { // reflect enemy bullet GameObject bullet = hit.gameObject; // Delfects an incoming bullet back at an enemy EnemyBullet reverse = (EnemyBullet)Instantiate(e_bullet, bullet.transform.position, Quaternion.identity); // Sets transfomr's parent for indicating, which player deflected the bullet reverse.transform.parent = transform.parent; reverse.set_duration(float.MaxValue); reverse.damage = damage / 3; // Sets bullet trajectory reverse.GetComponent <Rigidbody2D>().velocity = -hit.gameObject.GetComponent <Rigidbody2D>().velocity; Destroy(hit.gameObject); } return; } //keep track of last player to attack and update their scores lastPlayerToAttack = hit.transform.parent.gameObject; if (hit is Bullet1 || hit is Bullet2 || hit is Bullet3 || hit is Slash) { hit.transform.parent.gameObject.GetComponent <Player>().score.enemies_hit++; } // Pushback body.AddForce(hit.hitImpulse); // Take damage health -= hit.getDamage(); // Flash flash = 0.3f; if (hit is Bullet2 && GetComponent <GrowBoss>() != null) { // Grow Boss stops piercing bullets Destroy(hit.gameObject); } }
private void Fire() { // create a bullet EnemyBullet bullet = Instantiate(bulletPrefab, bulletParent.transform); // give it the same position as the player bullet.transform.position = transform.position; // play sound - AudioClip, Volume between 0 and 1 //AudioSource.PlayClipAtPoint(shootClip, Camera.main.transform.position,shootVolume); // use a local AudioSource audioSource.PlayOneShot(shootClip, shootVolume); // play health pickup sound //FindObjectOfType<AudioManager>().Play("HealthPowerUP"); Rigidbody2D rbb = bullet.GetComponent <Rigidbody2D>(); rbb.velocity = Vector2.down * bulletSpeed; }