void SpawnSecondary() { int count = UnityEngine.Random.Range(secondaryMissileMin, secondaryMissileMax); Vector2 pos = mTransform.position; Vector2 vel = mRigidBody.velocity; for (int i = 0; i < secondaryMissileMax; i++) { var go = factory.Add(secondaryMissile); var missile = go.GetComponent <Missile>(); float angle = UnityEngine.Random.Range(-Mathf.PI, Mathf.PI); float distance = UnityEngine.Random.Range(0.0f, explosiveRadius); float xOffset = Mathf.Cos(angle) * distance; float yOffset = Mathf.Sin(angle) * distance; missile.Fire(owner, pos + new Vector2(xOffset, yOffset), vel); } }
void FixedUpdate() { if (isAlive) { UpdateMovement(); } else if (!isAlive) { if (explosionMissile != null) { var explosion = missileFactory.Add(explosionMissile); explosion.Fire(this, mTransform.position, new Vector2(mVelocityX, mVelocityY)); } wave.enemies.Remove(this); gameObject.SetActive(false); } }
void FixedUpdate() { Vector3 nextMovement = kMovements[mMovementFlags]; mTransform.localPosition = mTransform.localPosition + nextMovement * mSpeed * Time.deltaTime; int hw = mHeight / 2; int y1 = (Screen.height / mRenderer.layer.scale) - hw; if (mTransform.localPosition.y < hw) { mTransform.localPosition = new Vector2(mTransform.localPosition.x, hw); } else if (mTransform.localPosition.y > y1) { mTransform.localPosition = new Vector2(mTransform.localPosition.x, y1); } msEnemyTargetX = mTransform.localPosition.x; msEnemyTargetY = mTransform.localPosition.y; if (nextMovement.y < 0) { if (mAnimator.spriteAnimation != verticalAnimations[0]) { mAnimator.spriteAnimation = verticalAnimations[0]; mAnimator.playing = true; mAnimator.time = 0.0f; } } else if (nextMovement.y > 0) { if (mAnimator.spriteAnimation != verticalAnimations[2]) { mAnimator.spriteAnimation = verticalAnimations[2]; mAnimator.playing = true; mAnimator.time = 0.0f; } } else if (mAnimator.spriteAnimation != verticalAnimations[1]) { mAnimator.spriteAnimation = verticalAnimations[1]; } if (mFireTimer > fireTime) { mFireTimer = 0.0f; var missile = missileFactory.Add(missilePrefabs[0]); Vector2 position = mTransform.position; position.x += mRenderer.sprite.width * 0.5f; missile.Fire(this, position, new Vector2(450.0f, 0.0f)); } if (mBombTimer < 0.0f) { mBombTimer = bombTime; Vector2 position = mTransform.position; position.x += mRenderer.sprite.width * 0.5f; var bomb = missileFactory.Add(bombPrefab); bomb.Fire(this, position, new Vector2(275.0f, 0.0f)); } }