private void Update() { if (active && Input.GetMouseButtonDown(0) && Time.time - lastTpTime >= coolDownTime) { RaycastHit hit; Ray ray = PCO.getPlayerCamera().ScreenPointToRay(Input.mousePosition); //Debug.Log("trying to identify"); RaycastHit2D hit2D = Physics2D.GetRayIntersection(ray);//test against 2d objects bool clickOnSomething = false; if (hit2D.collider != null) { clickOnSomething = true; return; } if (Physics.Raycast(ray, out hit, 100.0f)) //test against 3d objects { if (hit.transform != null) { clickOnSomething = true; } } if (!clickOnSomething) //we clicked on empty space you can spawn box { Vector3 mousePosition = PCO.getPlayerCamera().ScreenToWorldPoint(Input.mousePosition); PCO.CmdSpawnBoxOnPosition(new Vector3(mousePosition.x, mousePosition.y)); lastTpTime = Time.time; } } }
private void Update() { if (!active) { return; } bool canTeleport = Time.time - lastTpTime >= coolDownTime; if (!teleportActivated && canTeleport) //deactivate the visual effects(red color) { teleportActivated = true; if (coolDownRefernce) { coolDownRefernce.gameObject.SetActive(false); } AudioManager.instance.play("teleportActive"); } if (canTeleport && Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = PCO.getPlayerCamera().ScreenPointToRay(Input.mousePosition); //Debug.Log("trying to identify"); RaycastHit2D hit2D = Physics2D.GetRayIntersection(ray);//test against 2d objects bool clickOnSomething = false; if (hit2D.collider != null) { clickOnSomething = true; return; } if (Physics.Raycast(ray, out hit, 100.0f)) //test against 3d objects { if (hit.transform != null) { clickOnSomething = true; } } if (clickOnSomething) //cant teleport because clicked on something { AudioManager.instance.play("teleportBlocked"); } if (!clickOnSomething) //we clicked on empty space you can teleport { teleportActivated = false; lastTpTime = Time.time; if (coolDownRefernce) { coolDownRefernce.gameObject.SetActive(true); //activate cool down visuals } AudioManager.instance.play("teleporting"); Invoke("teleport", 0.3f); } } }
public bool isMouseToTheRight() { if (!playerCamera) { playerCamera = PCO.getPlayerCamera(); } if (!playerBoundingCollider) { playerBoundingCollider = PCO.playerBoundingCollider; } if (!playerCamera || !playerBoundingCollider) { Debug.Log("player character still not assigned"); return(true); } Vector3 mousePosition = Input.mousePosition; mousePosition = playerCamera.ScreenToWorldPoint(mousePosition); Vector2 clickDiffrence = mousePosition - playerBoundingCollider.transform.position; Transform player = playerBoundingCollider.transform; Vector3 slashDir = player.right; Vector2 A = player.up; Vector2 B = player.position - mousePosition; bool isleft = -A.x * B.y + A.y * B.x > 0; if (isleft) { return(false); } return(true); }