Created
December 11, 2015 17:05
-
-
Save twobob/003b067a65db7addb4a3 to your computer and use it in GitHub Desktop.
WorldToCanvasPosition supporting logic for GenerateTextObjectAndPositionDuringRuntime.cs
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; | |
public static class WorldToCanvasPosition { | |
// Use this for initialization | |
public static Vector2 ConvertWorldToCanvasPosition(RectTransform canvas, Camera camera, Vector3 position) | |
{ | |
Vector2 temp = camera.WorldToViewportPoint(position); | |
temp.x *= canvas.sizeDelta.x; | |
temp.y *= canvas.sizeDelta.y; | |
return temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment