JRyu
1
I want to create an UI-Button via script and position it in Worldspace so that it will be visible on Screen. I have a canvas that with the renderer mode set to world space. I can create a button via script. In the next step I want to position the button relative to the screen size but I dont know how convert the screen data into an actual 3D Position.
I hope you guys understand what I mean and thank you for answering.
JRyu
2
The answer that I found is to use the camera and the function ScreenToWorldPoint. The Method takes a Vector3 as an argumen. I created a new vector with the x and y coordinates that I want the UI Object to have on my screen and then I give it a z coordinate that I choose (The z does matter because of the size of the UI object, the further away from the camera the smaller it appears. I had to find what is best for my Objects). The method returns me a vector3 that represents this position in world-space. I use that position to instantiate the object.