public void EnemyDied() { deadEnemys++; if (deadEnemys >= maxEnemys) { if (altarBar.currPoints > 0) { pauseTime = maxPauseTime; healthBar.ChangeValue(15 + currWave); } else { NewWave(); } } }
// Update is called once per frame void FixedUpdate() { if (dyingTime == -1) { CheckForTarget(); if (currDelay > 0) { currDelay -= Time.deltaTime; } if (isWalkingPath) { //Debug.Log("Walking Path"); if (targetNode < path.Count) { Vector2 direction = (Vector2)path[targetNode].position - rb2d.position; direction.Normalize(); rb2d.velocity = direction * speed; canResetPath = false; if (Vector2.Distance(rb2d.position, path[targetNode].position) < 0.05f) { //Debug.Log(path[targetNode].position); rb2d.MovePosition(path[targetNode].position); //Debug.Log("d"); if (targetNode < path.Count - 1) { targetNode++; //Debug.Log(path[targetNode].position); } else { isWalkingPath = false; rb2d.velocity = Vector2.zero; pathDone = true; //Debug.Log("Path Done"); } canResetPath = true; } } } else if (Vector2.Distance(rb2d.position, CurrTargetPos()) < 2 && currDelay <= 0) { if (currTarget == 0) { altarBar.ChangeValue(-dmg); } else if (currTarget == 1) { healthBar.ChangeValue(-dmg); } currDelay = attackDelay; } //Debug.Log(pathDone); Vector2 velocity = (Vector2)rb2d.position - lastPos; string trigger = null; //Debug.Log(velocity); if (Mathf.Abs(velocity.x) >= Mathf.Abs(velocity.y) - 0.001) { if (velocity.x > 0.001) { trigger = "Right"; } else if (velocity.x < -0.001) { trigger = "Left"; } else { trigger = "Stand"; } } else { if (velocity.y > 0) { trigger = "Up"; } else if (velocity.y < 0) { trigger = "Down"; } } if (trigger != null) { GetComponent <Animator>().SetTrigger(trigger); } lastPos = rb2d.position; } else { rb2d.velocity = Vector2.zero; dyingTime += Time.deltaTime; if (dyingTime >= 2) { Destroy(gameObject); } } }