// Update is called once per frame void Update() { //mouse ray in unity's coordinate system (used for debug purposes only) var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var color = Input.GetMouseButton(0) ? Color.red : Color.white; Debug.DrawRay(ray.origin, ray.direction * 1000, color); //mouse ray in isometric coordinate system var isoRay = Isometric.MouseToIsoRay(); //do an isometric raycast on left mouse click if (Input.GetMouseButtonDown(0)) { IsoRaycastHit isoRaycastHit; if (IsoPhysics.Raycast(isoRay, out isoRaycastHit)) { Debug.Log("we clicked on " + isoRaycastHit.Collider.name + " at " + isoRaycastHit.Point); SpawnFlower(isoRaycastHit.Point); StartCoroutine(Blink(isoRaycastHit.IsoTransform.GetComponent <SpriteRenderer>(), Color.red)); } } }
public void Update() { // Handle mouse movement if (Input.GetMouseButtonDown(0) && !mouseDebounce && trackMouse) { trackMouse = false; var isoRay = Isometric.MouseToIsoRay(); //do an isometric raycast on left mouse click if (Input.GetMouseButtonDown(0)) { IsoRaycastHit isoRaycastHit; if (IsoPhysics.Raycast(isoRay, out isoRaycastHit)) { selectedObj = isoRaycastHit.IsoTransform; // Update instruction text component2 = new InstructionComponent("X: " + selectedObj.Position.x + " Z: " + selectedObj.Position.z) { OnComponentClicked = onClicked }; targetPos = new Vector3(selectedObj.Position.x, 1, selectedObj.Position.z); instructionRenderer.Render(); } } if (instructionRenderer != null) { instructionRenderer.BackgroundColor = instructionRenderer.DefaultBackgroundColor; } } mouseDebounce = false; }
bool CastRayFromMouse() { var isoRay = Isometric.MouseToIsoRay(); return(IsoPhysics.Raycast(isoRay, out isoRaycastHit)); }
// Update is called once per frame void FixedUpdate() { // give a small gap before dragging, preventing that when user clicks on the DraggableIsoItem, the mouse is // also firing at the IsoDropZone besides it, causing the block to be shifted to the drag zone beside if (_dragging && Time.time - lastClickTime > 0.1f) { // fire a ray cast from the current mouse position to the Isometric dimension system var isoRay = Isometric.MouseToIsoRay(); IsoRaycastHit isoRaycastHit; if (IsoPhysics.Raycast(isoRay, out isoRaycastHit)) { // if the ray cast hits something, check which tile is it hitting, trigger entering the drop zone // and exiting the previous drop zone var hitCollider = isoRaycastHit.Collider; if (hitCollider != _currentHitCollider) { // if the ray cast did not hit any tile, the block is moved to an empty space, trigger exiting the // previous drop zone if (_currentHitCollider != null) { OnIsoTriggerExitDZ(_currentHitCollider); } OnIsoTriggerEnterDZ(hitCollider); _currentHitCollider = hitCollider; } } else { if (_currentHitCollider != null) // The block is leaving the drop zone { OnIsoTriggerExitDZ(_currentHitCollider); _currentHitCollider = null; } } // Move the block visually var localMousePos = Input.mousePosition; var mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(localMousePos.x, localMousePos.y, Camera.main.nearClipPlane)); var diff = mousePosWorld - _prevMousePos; GetComponent <IsoTransform>().transform.Translate(diff); if (dropZone != null) { dropZone.OnItemDrag(this); } _prevMousePos = mousePosWorld; } if (_moving) // The block is moving to its new drop zone { _civilLevelController.ToggleGameControlButtons(false); transform.position = Vector3.Lerp(transform.position, _target, 0.1f); // Transform the position with an animation if (Vector3.Distance(transform.position, _target) < 0.01f) { // Actually move the block there GetComponent <IsoTransform>().Position = dropZone.GetComponent <IsoTransform>().Position; _civilLevelController.ToggleGameControlButtons(true); _moving = false; } } }