void Update() { if (Health <= 0) { WS.EnemyDie(); Destroy(this.gameObject); } if (hit) { sr.material = matWhite; Invoke("resetWhite", 0.01f); } else { sr.material = matDefualt; } }
private void Update() { if (Health <= 0) { WS.EnemyDie(); Destroy(this.gameObject); } Vector3 direction = playerPosition.position - transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + 90; rb.rotation = angle; transform.position = Vector2.MoveTowards(transform.position, playerPosition.position, SpeedMovement * Time.deltaTime); if (hit) { sr.material = matWhite; Invoke("resetWhite", 0.01f); } else { sr.material = matDefualt; } }