/************************* * Main Update Loop **************************/ void FixedUpdate() { //If no path do nothing check if (path == null) { return; } //if end of path update bools if (currentWaypoint >= path.vectorPath.Count) { reachedEndofPath = true; return; } else { reachedEndofPath = false; } if (!stunned) //if enemy is stunned they cannot do anything { MovetowardsTargetPosition(); FaceConeToTarget(); CheckIfPlayerIsDetected(); //continue to next waypoint float distance = Vector2.Distance(rb.position, path.vectorPath[currentWaypoint]); if (distance < nextWaypoitnDistance) { currentWaypoint++; } } else //stunned { stuntime -= Time.deltaTime; if (stuntime < 0) { stunned = false; globalalert.GlobalAlertOn(); stuntime = 3f; } } }
private void OnTriggerEnter2D(Collider2D collider) { if (collider.CompareTag("Enemy")) { collider.GetComponent<EnemyScript>().gethit(5); } if (collider.CompareTag("Player")) { collider.GetComponent<MCMovement>().DamagePlayer(5); } if (!playingmusic) { playingmusic = true; alertscript.GlobalAlertOn(); audioSource.PlayOneShot(explosion, 7f); thissprite.enabled = false; thiscollider.enabled = false; Destroy(gameObject, 7f); } }