This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// calculate distance between two LAT LON values | |
// Note: In this formula, the latitudes and longitudes are expressed in radians. 6371 is radius of the earth in km | |
// SOURCE: codinggame.com | |
var earthRadius = 6371; | |
var x = (lonB-lonA)*Math.cos((latA+latB)/2); | |
var y = (latB-latA); | |
var d = Math.sqrt(x*x+y*y)*earthRadius; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public LayerMask yourLayer = 1 << 10; // 10 | |
gameObject.layer = (int)Mathf.Log(yourLayer.value, 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://forum.unity.com/threads/overlay-canvas-and-world-space-coordinates.291108/#post-9627593 | |
// translating between overlay canvas and world space coordinates | |
uiObject.transform.position = RectTransformUtility.WorldToScreenPoint(Camera.main, worldObject.transform.TransformPoint(Vector3.zero)); | |
-------- | |
// http://answers.unity3d.com/questions/799616/unity-46-beta-19-how-to-convert-from-world-space-t.html | |
//this is your object that you want to have the UI element hovering over |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3[] corners = new Vector3[4]; | |
rectTransform1.GetWorldCorners(corners); | |
Rect rec = new Rect(corners[0].x,corners[0].y,corners[2].x-corners[0].x,corners[2].y-corners[0].y); | |
rectTransform2.GetWorldCorners(corners); | |
Rect rec2 = new Rect(corners[0].x, corners[0].y,corners[2].x-corners[0].x,corners[2].y-corners[0].y); | |
if (rectTransform1.Overlaps(rectTransform2)) | |
{ | |
Debug.Log("rectTransform1 is Overlapping rectTransform2!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scene setup: | |
// CanvasCamera (canvasCam) with ScreenSpace-Camera UI canvas & elements (in different position from main camera) | |
// MainCamera (mainCam) | |
// UI image (obj) inside the CanvasCamera canvas | |
var originalScreenPos = canvasCam.WorldToScreenPoint(obj.position); | |
var worldPosInMainCamera = mainCam.ScreenToWorldPoint(p1); | |
var rayDirection = (worldPosInMainCamera-mainCam.transform.position); | |
Debug.DrawRay(mainCam.transform.position, rayDirection * 999, Color.red); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X55b4f2f6990d5ca7a8X |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// attach this scrip to the camera you want to draw your rt from elsewhere | |
public class DrawRT : MonoBehaviour | |
{ | |
public RenderTexture rt; // render to this rt from another camera | |
Camera cam; | |
Rect cameraViewRect; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://answers.unity3d.com/questions/997174/unity-ui-rendertexture-broken-since-501p4.html *lower camera depth for rendertexture cam | |
http://forum.unity3d.com/threads/ui-flicker-screen-space-overlay-render-texture.375712/#post-2448703 *render camera manually in code | |
http://answers.unity3d.com/questions/1092350/unity-5-gui-fllickering-artefacts-on-android.html *fixed in unity version 5.3? | |
http://forum.unity3d.com/threads/5-3-elements-in-the-ui-flicker-between-different-sprites.373098/page-4#post-2486347 *patch version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// blog post: https://unitycoder.com/blog/2016/03/01/latitude-longitude-position-on-3d-sphere-v2/ | |
using UnityEngine; | |
public class LatLong : MonoBehaviour | |
{ | |
public Transform marker; // marker object | |
public float radius = 5; // globe ball radius (unity units) | |
public float latitude = 51.5072f; // lat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://forum.unity3d.com/threads/create-2d-collider-based-on-non-transparent-pixels.390051/#post-2544449 | |
/// <summary> | |
/// ClockwiseComparer provides functionality for sorting a collection of Vector2s such | |
/// that they are ordered clockwise about a given origin. | |
/// </summary> | |
public class ClockwiseComparer : IComparer<Vector2> | |
{ | |
private Vector2 m_Origin; | |
/// <summary> |