-
Notifications
You must be signed in to change notification settings - Fork 131
How to use Futile as UI and track the position of 3D objects in 2D
Matt Rix edited this page Sep 11, 2013
·
1 revision
To use Futile as a UI system, do this after calling Futile.instance.Init():
Futile.instance.camera.cullingMask = 1 << 11; //only render layer 11 with the Futile camera, nothing else
Futile.instance.camera.clearFlags = CameraClearFlags.Depth; //don't clear the screen before drawing Futile
Futile.stage.layer = 11; //make all Futile stuff get created on layer 11Also, go into the Unity layers and name layer 11 to "Futile", and set the camera for your 3D scene's culling mask to have everything except the Futile layer (this means it'll render everything except Futile).
Now for example, let's say you want myNode in Futile (in 2D) to track the position of "thingToFollow", a regular Unity Transform (in 3D), here's what you can do:
Vector3 thingPos = threeDeeCamera.WorldToScreenPoint(thingToFollow.position); //position of the object on the screen
Vector2 localPos = myNode.container.ScreenToLocal(new Vector2(thingPos.x,thingPos.y)); //convert to Futile coords
myNode.SetPosition(localPos); //move the node to that position