protected override void Update() { //Do BaseAttacker's Update first base.Update(); //Update bullet UpdateBullet(); //If player inputs the shoot key if (Input.GetMouseButton(0)) { //If player can attack //And cursor is locked to center if (CanAttack && Cursor.lockState == CursorLockMode.Locked) { //Set cooltime SetAttackCooltime(); //Show the bullet shot ShowBullet(); //Play audio fireAudio.Stop(); fireAudio.Play(); //Do a raycast from bullet source RaycastHit hit; if (Physics.Raycast(myCamera.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0f)), out hit, attackRange, targetLayer.value)) { //Try to get the enemy entity object EnemyEntity enemy = hit.collider.GetComponent <EnemyEntity>(); //If it is a valid enemy if (enemy != null) { //Damage the enemy enemy.DoDamage(damage); } } } } //If player presses the flashlight toggle key if (Input.GetKeyDown(KeyCode.Z)) { //Toggle light enable state flashlight.enabled = !flashlight.enabled; } }