void Update() { if (CurrentStage == Stage.Normal) { if (!hp.isDead) { float angle = Mathf.Atan2(Player.transform.position.y - transform.position.y, Player.transform.position.x - transform.position.x); float newX = move_speed * Mathf.Cos(angle); float newY = move_speed * Mathf.Sin(angle); rb.velocity = new Vector2(newX * 1.5f, newY); if (DetectRange >= Vector3.Distance(Player.transform.position, transform.position)) { CurrentStage = Stage.PlayerDetected; timer = DashDelay; } } } else if (CurrentStage == Stage.PlayerDetected) { timer -= Time.deltaTime; if (timer <= 0 && !hp.isDead) { if (!setPosition) { PlayerLastPosition = Player.transform.position; float angle = Mathf.Atan2(PlayerLastPosition.y - transform.position.y, PlayerLastPosition.x - transform.position.x); setPosition = true; float newX = dash_speed * Mathf.Cos(angle); float newY = dash_speed * Mathf.Sin(angle); rb.velocity = new Vector2(newX, newY); } if (Vector3.Distance(PlayerLastPosition, transform.position) < 1) { rb.velocity = Vector2.zero; Explode.Invoke(); hp.StartCoroutine(hp.Dead(1)); } } else { rb.velocity = Vector2.zero; } } }
public void Dead() { GameObject effect = spawner.GetObjectFromPool("BeaconEffect"); effect.transform.position = this.transform.position; player.hp = player.Maxhp; ui.score += ui.BeaconScore; hp.StartCoroutine(hp.Dead(1)); }
public void Dead() { ui.score += ui.EnemyScore; GameObject.Find("Spawner").GetComponent <SpawnSystem>().GetObjectFromPool("Effect").transform.position = this.transform.position; hp.StartCoroutine(hp.Dead(1)); }