void OnTriggerEnter2D(Collider2D coll) { BoomerangBehaviour boom = coll.GetComponent <BoomerangBehaviour>(); if (boom) { switch (m_ActionWhenUse) { case Action.Activate: if (m_Status != Interactable.Status.Activated) { this.Activate(); } break; case Action.Deactivate: if (m_Status != Interactable.Status.Deactivated) { this.Deactivate(); } break; case Action.Toggle: if (m_Status == Interactable.Status.Deactivated) { this.Activate(); } else { this.Deactivate(); } break; } } }
void ShootBoomerang() { if (GameManager.instance.BoomerangCount > 0) { // Raycast towards the mouse click Ray _clickRay = mainCamera.ScreenPointToRay(Input.mousePosition); // Get the poin where the ray hits RaycastHit _rayHit; if (Physics.Raycast(_clickRay, out _rayHit, 100f)) { // Instantiate boomerang boomerang = Instantiate(boomerangPrefab).GetComponent <BoomerangBehaviour>(); boomerang.transform.SetPositionAndRotation(transform.position, Quaternion.identity); // Get a line from the screen center until the hit point //Debug.DrawLine(transform.position, _rayHit.point, Color.red); // Get throwing direction _throwDirection = (_rayHit.point - transform.position); // Add force to the boomerang towards the target _throwForce = Mathf.Max(_chargeDuration / maxChargeDuration * throwMaxForce, throwMinForce); boomerang.GetComponent <Rigidbody>().AddForce(_throwDirection * _throwForce, ForceMode.Impulse); boomerang.GetComponent <BoomerangBehaviour>().returnDirection = _throwDirection * _throwForce * -2; // Play sound boomerangSource.Play(); GameManager.instance.UseBoomerang(); } } }
void OnTriggerEnter2D(Collider2D coll) { BoomerangBehaviour boom = coll.GetComponent <BoomerangBehaviour>(); if (boom) { boom.Pick(); m_HasBoomerang = true; } }
void StraightThrow() { if (!m_HasBoomerang) { return; } BoomerangBehaviour boom = Instantiate(boomerangBrefab, transform.position, Quaternion.identity).GetComponent <BoomerangBehaviour>(); boom.StraightThrow(transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition)); m_HasBoomerang = false; }