/// <summary> /// Triggers the hammer animation and hitting the target /// </summary> /// <param name="target"></param> /// <returns></returns> IEnumerator HammerActionRoutine(IHammerHittable target) { IsMovementDisabled = true; m_canHammer = false; m_hammerHasHit = false; // Before hammering, if we are moving we must wait until reaching the destination while (m_isMoving) { yield return(null); } // If the target can still be hit, then hit it if (target.CanBeHit()) { m_animator.SetTrigger("Hammer"); target.OnHammerHit(); // Wait until the hammer connects and triggers the expected result before resuming control while (!target.HitProcessed()) { yield return(null); } } m_canHammer = true; m_hammerTriggered = false; IsMovementDisabled = false; }
/// <summary> /// Handles player mouse inputs /// </summary> void HandleMouseInput() { if (!ControlsEnabled) { return; } // Not clicking on anything if (m_mouseToggle && !Input.GetButtonDown("Fire1")) { return; } else if (!m_mouseToggle && !Input.GetButton("Fire1")) { return; } else { m_hammerButtonReleased = true; } // Already triggered - wait until it is done if (!m_hammerTriggered && m_hammerButtonReleased) { // Create a ray from the mouse cursor on screen in the direction of the camera. Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition); // Create a RaycastHit variable to store information about what was hit by the ray. RaycastHit hit; Debug.DrawRay(camRay.origin, camRay.direction); // Perform the raycast and if it hits something on the floor layer... if (Physics.Raycast(camRay, out hit, m_camRayLength, m_hamerHitLayer)) { IHammerHittable target = hit.collider.GetComponent <IHammerHittable>(); Tile tile = hit.collider.GetComponent <Tile>(); if (target != null && tile != null && target.CanBeHit()) { TriggerHammerAction(target); } } } }