// Use this for initialization void Start() { magicBullet = new MagicBullet(); magicBullet.speed = speed; magicBullet.collided = false; if (!isRight) { magicBullet.speed = -magicBullet.speed; } body = GetComponent <Rigidbody2D>(); if (magicBullet.collided) { body.velocity = Vector3.zero; } else { body.velocity = new Vector2(magicBullet.speed, body.velocity.y); } StartCoroutine("timeToLive"); gameObject.GetComponent <Collider2D>().isTrigger = true; }
void Attack(Damage dmg) { GameObject bullet = Instantiate(bulletPrefab) as GameObject; MagicBullet bulletCom = bullet.GetComponent <MagicBullet> (); Block block = BattleField.GetBlock(dmg.target); bulletCom.Shoot(block.GetCenterPosition()); parent.SendDamage(dmg); }
IEnumerator Attack(Block block, float delay) { yield return(new WaitForSeconds(delay)); GameObject bullet = Instantiate(bulletPrefab) as GameObject; MagicBullet bulletCom = bullet.GetComponent <MagicBullet> (); bulletCom.Shoot(block.GetCenterPosition()); if (block.state == Block.BlockState.Hero) { SendDamage(GetDamage(parent.GetHeroInfo(), block.SimpleBlock), block); } }
protected override void OnUpdate() { OnUpdateHitbox(); HandleBlinking(); if (frozenTimeLeft > 0) { frozenTimeLeft -= Time.TimeMult; return; } MoveInstantly(new Vector2(speedX, speedY), MoveType.RelativeTime, true); if (playerHit) { if (attackTime > 0f) { attackTime -= Time.TimeMult; } else { base.OnPerish(null); } return; } if (attackTime > 0f) { attackTime -= Time.TimeMult; } Vector3 pos = Transform.Pos; Vector3 targetPos; List <Player> players = api.Players; for (int i = 0; i < players.Count; i++) { targetPos = players[i].Transform.Pos; // Fly above the player targetPos.Y -= 100f; Vector3 direction = (pos - targetPos); float length = direction.Length; if (attackTime <= 0f && length < 260f) { attackTime = 450f; PlaySound("MagicFire"); SetTransition(AnimState.TransitionAttack, true, delegate { Vector3 bulletPos = Transform.Pos + new Vector3(24f * (IsFacingLeft ? -1f : 1f), 0f, -2f); MagicBullet bullet = new MagicBullet(this); bullet.OnAttach(new ActorInstantiationDetails { Api = api, Pos = bulletPos }); api.AddActor(bullet); Explosion.Create(api, bulletPos, Explosion.TinyDark); }); } else if (length < 500f) { direction.Normalize(); speedX = (direction.X * DefaultSpeed + speedX) * 0.5f; speedY = (direction.Y * DefaultSpeed + speedY) * 0.5f; IsFacingLeft = (speedX < 0f); return; } } speedX = speedY = 0; }