public override void Attack(GameObject enemyGameObject) { if (attackWait > 0) { attackWait -= Time.deltaTime; return; } Vector3 bulletPosition = enemyGameObject.transform.position; // ランダムな角度に弾を撃つ float angle = Random.Range(-90, 291); float rad = angle * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * 1.3f; bulletPosition.y += Mathf.Cos(rad) * 1.3f; GameObject bulletObject = GameObject.Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Enemy_Bullet_00_small")); BulletMain bulletMain = bulletObject.GetComponent <BulletMain>(); bulletMain.Fire(bulletPosition, angle, this.bulletSpeed, 1, BulletTarget.Player); attackWait = defaultAttackWait; }
public void EndFire() { // 狙撃の場合 if (selectPlayer.gameObjectName == playerSogeki.gameObjectName) { if (this.selectPlayer.IsDamageWait()) { this.SetSogekiEffect(0); return; } if (this.nowChargeLevel >= 3) { // 弾の初期位置を砲台の位置までずらす Vector3 bulletPosition = this.selectPlayer.gameObject.transform.position; float rad = this.selectPlayer.angle * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * this.selectPlayer.fireConfig.margin; bulletPosition.y += Mathf.Cos(rad) * this.selectPlayer.fireConfig.margin; // 狙撃は発射位置が右に少しずれているため調整する float rightMargin = 0.06f; rad = (this.selectPlayer.angle - 90) * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * rightMargin; bulletPosition.y += Mathf.Cos(rad) * rightMargin; GameObject bulletObject = Instantiate(this.selectPlayer.fireConfig.bulletGameObject); BulletMain bulletMain = bulletObject.GetComponent <BulletMain>(); // TODO 長押し時間に応じてangleを散らす bulletMain.Fire(bulletPosition, this.selectPlayer.angle, 0.20f, this.selectPlayer.fireConfig.damage, BulletTarget.Enemy); soundManager.PlayAudioClip(SoundManager.AudioClipType.GUNSHOT_FANTOM01); } this.sogekiChargeCount = 0; this.SetSogekiEffect(0); } // 拡散の場合 else if (this.selectPlayer.gameObjectName == this.playerKakusan.gameObjectName) { this.selectPlayer.fireConfig.isFire = false; if (this.selectPlayer.IsDamageWait()) { return; } float rad; // 11 方向に弾を出す for (int i = -5; i <= 5; i++) { Vector3 bulletPosition = this.selectPlayer.gameObject.transform.position; rad = (this.selectPlayer.angle + i * 5) * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * this.selectPlayer.fireConfig.margin; bulletPosition.y += Mathf.Cos(rad) * this.selectPlayer.fireConfig.margin; GameObject bulletObject = Instantiate(this.selectPlayer.fireConfig.bulletGameObject); BulletMain bulletMain = bulletObject.GetComponent <BulletMain>(); bulletMain.Fire(bulletPosition, (this.selectPlayer.angle + i * 5), 0.1f, this.selectPlayer.fireConfig.damage, BulletTarget.Enemy); } GameObject muzzleObject = Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Player_01_kakusan_muzzle")); Vector3 muzzlePosition = this.selectPlayer.gameObject.transform.position; rad = this.selectPlayer.angle * Mathf.Deg2Rad; muzzlePosition.x -= Mathf.Sin(rad) * 0.6f; muzzlePosition.y += Mathf.Cos(rad) * 0.6f; muzzleObject.gameObject.transform.position = muzzlePosition; muzzleObject.gameObject.transform.rotation = this.selectPlayer.gameObject.transform.rotation; soundManager.PlayAudioClip(SoundManager.AudioClipType.MISSILE); } else { this.selectPlayer.gameObject.transform.Find("Player_00_rensya_muzzle_left").gameObject.SetActive(false); this.selectPlayer.gameObject.transform.Find("Player_00_rensya_muzzle_right").gameObject.SetActive(false); this.selectPlayer.fireConfig.isFire = false; } }
public override void Attack(GameObject enemyGameObject) { if (attackWait > 0) { attackWait -= Time.deltaTime; if (this.type == 2) { /* * if (this.bulletLine == null) * { * this.bulletLine = (GameObject)Object.Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/ShotLine"), enemyGameObject.transform.position, Quaternion.identity); * this.bulletLine.transform.parent = enemyGameObject.transform; * this.bulletLine.transform.position = new Vector3(this.bulletLine.transform.position.x, this.bulletLine.transform.position.y -50 / 2, 0); * this.bulletLine.SetActive(true); * } */ } return; } // TODO 自機を狙うようにする // 連射タイプ if (this.type == 1) { Vector3 bulletPosition = enemyGameObject.transform.position; bulletPosition.y -= 0.5f; GameObject bulletObject = GameObject.Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Enemy_Bullet_00_small")); BulletMain bulletMain = bulletObject.GetComponent <BulletMain>(); bulletMain.Fire(bulletPosition, Random.Range(160, 200), this.bulletSpeed, 1, BulletTarget.Player); } // レーザータイプ else { Vector3 bulletPosition = enemyGameObject.transform.position; // 位置が変なので調整 bulletPosition.x -= 0.04f; bulletPosition.y -= 0.33f; GameObject bulletObject = GameObject.Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Enemy_Bullet_02_laser")); bulletObject.transform.position = bulletPosition; Vector3 rot = bulletObject.transform.eulerAngles; int targetNum = Random.Range(0, 4); string targetObjectName = ""; switch (targetNum) { case 0: targetObjectName = "Player_rensya"; break; case 1: targetObjectName = "Player_kakusan"; break; case 2: targetObjectName = "Player_sogeki"; break; case 3: targetObjectName = "Background_Earth"; break; default: break; } GameObject targetObject = GameObject.Find(targetObjectName); Vector2 sub = Camera.main.ScreenToWorldPoint(bulletObject.transform.position) - Camera.main.ScreenToWorldPoint(targetObject.transform.position); float angle = Mathf.Atan2(sub.y, sub.x) * Mathf.Rad2Deg - 90f; rot.z = angle; bulletObject.transform.eulerAngles = rot; //BulletMain bulletMain = bulletObject.GetComponent<BulletMain>(); //bulletMain.Fire(bulletPosition, Random.Range(-45, 45), 0, 1, BulletTarget.Player); GameObject shotEffectObject = GameObject.Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Enemy_Bullet_01_laser_moto")); // 位置が変なのでさらに調整 bulletPosition.y -= 0.25f; shotEffectObject.transform.position = bulletPosition; } /* * float rad = this.selectPlayer.angle * Mathf.Deg2Rad; * bulletPosition.x -= Mathf.Sin(rad) * this.selectPlayer.fireConfig.margin; * bulletPosition.y += Mathf.Cos(rad) * this.selectPlayer.fireConfig.margin; * * GameObject bulletObject = Instantiate(this.selectPlayer.fireConfig.bulletGameObject); * BulletMain bulletMain = bulletObject.GetComponent<BulletMain>(); * bulletMain.Fire(bulletPosition, this.selectPlayer.angle, 0.20f, this.selectPlayer.fireConfig.damage, BulletTarget.Enemy); */ attackWait = defaultAttackWait; }
private void Fire() { // ショットアニメーション(とりあえず連射だけ) if (this.selectPlayer.gameObjectName == this.playerRensha.gameObjectName) { this.selectPlayer.gameObject.GetComponent <Animator>().SetBool("ModelShotPlayerRensha", this.selectPlayer.fireConfig.isFire); } if (this.selectPlayer.IsDamageWait()) { return; } if (!this.selectPlayer.fireConfig.isFire) { this.selectPlayer.fireConfig.wait = 0; return; } this.selectPlayer.fireConfig.wait -= Time.deltaTime; if (this.selectPlayer.fireConfig.wait <= 0.0) { // 拡散 if (this.selectPlayer.gameObjectName == this.playerKakusan.gameObjectName) { this.selectPlayer.fireConfig.wait = 1.0f / selectPlayer.fireConfig.firePerFrame; // TODO ウェイトを変える float rad; // 押下時に複数弾を作って攻撃し、フラグは立てない(長押しで何もしない) for (int i = -5; i <= 5; i++) { Vector3 bulletPosition = this.selectPlayer.gameObject.transform.position; rad = (this.selectPlayer.angle + i * 5) * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * this.selectPlayer.fireConfig.margin; bulletPosition.y += Mathf.Cos(rad) * this.selectPlayer.fireConfig.margin; GameObject bulletObject = Instantiate(this.selectPlayer.fireConfig.bulletGameObject); BulletMain bulletMain = bulletObject.GetComponent <BulletMain>(); bulletMain.Fire(bulletPosition, (this.selectPlayer.angle + i * 5), 0.1f, this.selectPlayer.fireConfig.damage, BulletTarget.Enemy); } GameObject muzzleObject = Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Player_01_kakusan_muzzle")); Vector3 muzzlePosition = this.selectPlayer.gameObject.transform.position; rad = this.selectPlayer.angle * Mathf.Deg2Rad; muzzlePosition.x -= Mathf.Sin(rad) * 0.6f; muzzlePosition.y += Mathf.Cos(rad) * 0.6f; muzzleObject.gameObject.transform.position = muzzlePosition; muzzleObject.gameObject.transform.rotation = this.selectPlayer.gameObject.transform.rotation; } // 連射 else { this.selectPlayer.fireConfig.wait = 1.0f / selectPlayer.fireConfig.firePerFrame; // 左側の弾の初期位置を砲台の位置までずらす Vector3 bulletPosition = this.selectPlayer.gameObject.transform.position; float rad = (this.selectPlayer.angle + 7) * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * this.selectPlayer.fireConfig.margin; bulletPosition.y += Mathf.Cos(rad) * this.selectPlayer.fireConfig.margin; GameObject bulletObject = Instantiate(this.selectPlayer.fireConfig.bulletGameObject); BulletMain bulletMain = bulletObject.GetComponent <BulletMain>(); bulletMain.Fire(bulletPosition, this.selectPlayer.angle, 0.20f, this.selectPlayer.fireConfig.damage, BulletTarget.Enemy); // 右側の弾 bulletPosition = this.selectPlayer.gameObject.transform.position; rad = (this.selectPlayer.angle - 7) * Mathf.Deg2Rad; bulletPosition.x -= Mathf.Sin(rad) * this.selectPlayer.fireConfig.margin; bulletPosition.y += Mathf.Cos(rad) * this.selectPlayer.fireConfig.margin; bulletObject = Instantiate(this.selectPlayer.fireConfig.bulletGameObject); bulletMain = bulletObject.GetComponent <BulletMain>(); bulletMain.Fire(bulletPosition, this.selectPlayer.angle, 0.20f, this.selectPlayer.fireConfig.damage, BulletTarget.Enemy); // 発射エフェクト this.selectPlayer.gameObject.transform.Find("Player_00_rensya_muzzle_left").gameObject.SetActive(true); this.selectPlayer.gameObject.transform.Find("Player_00_rensya_muzzle_right").gameObject.SetActive(true); soundManager.PlayAudioClip(SoundManager.AudioClipType.MACHINEGUN); } } }