- Home /
Find the world position of an object rendered on a scaled Render Texture
The game I am currently working on requires the GUI to be rendered within a safe frame of the screen. We're being constrained to using Unity 4.3 so are unable to make use of the new Unity GUI features, so instead we are using Render Textures to display the GUI and then scale the textures depending on percentage of safe frame required.
For one scenario we need to display a lot of text, so being stuck with 4.3, I am using OnGUI() to draw a scroll rect and have all the text within these bounds. However, due to the need of a safe frame which is scaled to a render texture, whenever we adjust the safe frame percentage the position we want the GUI scroll rect to be drawn at is offset because it can't be rendered on the render texture.
My current solution involves having a game object in world space which represents the position I want to draw the scroll rect (currently I have a sprite there to help visualise position). This is then drawn on the render texture and scaled based on safe frame, but obviously now the render position of my object does not match the world position and I can't figure out how to convert the world position be a scaled texture to the GUI screen position.
Below is code I've currently been trying, but doesn't work. While the render texture position is scaled closer to the center of the screen, the GUI scroll position goes to the outside of the screen.
Vector3 screen_Position = camera.WorldToScreenPoint(world_Position);
Vector3 position = screen_Position;
// Adjust the position by the safe zone
position.x *= Options_Manager.Instance.SafeZone;
position.y *= Options_Manager.Instance.SafeZone;
I'm not sure how to convert the world position to get the scaled render texture position. Any help would be greatly appreciated! Thank you! :)
Your answer
Follow this Question
Related Questions
Changing camera position to shoot through scope on gun 1 Answer
How do I tell a button to move my camera!? 1 Answer
How Can I Stop Rotation From This Script? 0 Answers
Increase Field of View without move some objects 1 Answer
Camera shake 11 Answers