private IEnumerator Firing() { float fireDelay = 0.15f; //todo field foreach (Transform target in m_lockOns) { var homingMissile = m_missilePool.GetFromPool().GetComponent <HomingMissile>(); homingMissile.TargetLock = target; m_lockOnIcons[target].MissileLaunched = true; m_lockOnIcons[target].Missile = homingMissile; Vector2 randomSpawnDirection = Random.insideUnitCircle.normalized; randomSpawnDirection = new Vector2(randomSpawnDirection.x, Mathf.Abs(randomSpawnDirection.y)); homingMissile.transform.position = transform.position + (Vector3)randomSpawnDirection * 0.5f; homingMissile.Body.AddForce(randomSpawnDirection * LaunchImpulse, ForceMode2D.Impulse); homingMissile.transform.rotation = Quaternion.LookRotation( Vector3.back, target.position - homingMissile.transform.position); homingMissile.StartChase(); yield return(new WaitForSeconds(fireDelay)); } m_lockOns.Clear(); m_lockOnIcons.Clear(); m_weaponState = EWeaponState.neutral; }
protected override void Shoot() { var shot = m_bulletPool.GetFromPool(); shot.transform.position = transform.position + (Vector3)BulletSpawnOffsetPosition; var bulletScript = shot.GetComponent <Bullet>(); bulletScript.RigidBody.velocity = new Vector2(0f, bulletScript.BulletSpeedProp); }
private IEnumerator Locking() { RaycastHit2D[] hits; LayerMask layer = 1 << LayerMask.NameToLayer("Enemies"); while (m_weaponState == EWeaponState.locking) { hits = Physics2D.RaycastAll(transform.position, Vector2.up, LockOnDistance, layer); foreach (var item in hits) { if (!m_lockOns.Contains(item.transform)) { m_lockOns.Add(item.transform); var icon = m_lockOnIconPool.GetFromPool().GetComponent <LockOnIcon>(); icon.FollowTarget = item.transform; m_lockOnIcons.Add(item.transform, icon); } } yield return(null); } }