private void OnMouseOver() { if (m_isFired) { return; } if (Input.GetMouseButtonDown(0)) { // Left click to throw m_objectController.Throw(transform.position, m_throwDirection * m_throwForce); m_isFired = true; } if (Input.GetMouseButtonDown(1)) { Debug.Log("Pressed secondary button."); // Right click to break m_objectController.Break(); m_isFired = true; } }
private void Throw(InputActionEventData data) { if (m_status.CanAct && m_canThrow && m_objectStack.Count > 0) { RuntimeManager.PlayOneShot(m_throwSound); m_anim.SetTrigger(AnimationConst.Throw); ObjectController obj = m_objectStack.Dequeue(); obj.transform.DOComplete(); Vector2 throwDir = m_status.FacingDir * m_status.ThrowForce; RaycastHit2D hit = Physics2D.Raycast(transform.position, m_status.FacingDir, Mathf.Infinity, m_throwTargetLayer); if (hit.collider != null) { throwDir = ((Vector2)hit.transform.position - (Vector2)obj.transform.position).normalized * m_status.ThrowForce; } obj.Throw(obj.transform.position, throwDir); ReorganizeStack(); m_lastThrowTime = Time.time; m_canThrow = false; } m_anim.SetBool(AnimationConst.Carry, m_objectStack.Count > 0); }