I have used Camera.mainCamera.WorldToViewportPoint to determine where a
GUIText has to appear depending of another
GameObject. Now, I need to instantiate another
GameObject depending of the
GUIText position wich has changed meanwhile. Could you tell me how to do it please?
This is how I did the first task, and I would like to do it in a similar way:
Vector3 pos = Camera.mainCamera.WorldToViewportPoint(transform.position);
GameObject foo = (GameObject)Instantiate(bar ,new Vector3(pos.x,pos.y,pos.z),Quaternion.identity);
You should use ViewportToWorldPoint - but there’s a small trick: you must pass the viewport coordinates in x and y, and in z you must inform the distance the 3D point will be from the camera. A viewport 2D point corresponds in the 3D world to a ray starting at the camera and passing through the point, so you must tell where in this line the point will be.
NOTE: The Your answer box must be used only to answer the question - for replies or comments use the minuscule add new comment button which exists in questions and answers. People get confused if you post anything but an answer via answer box - I almost passed over your question because I thought it was already answered! It would be better to copy your answer’s text, delete that answer, click add new comment and paste the text there (thus converting the answer into a comment).