Generating a particle effect on top of a GUIElement

I have a number of guitextures which are hearts in order to create a sort of life meter. I would like when the player loses a heart for the heart to change into a skull in a puff of smoke. I currently have the hearts correctly turning into skulls, and a puff of smoke is generated, however the smoke is created in the wrong location.

The smoke is currently generated by:

GameObject smokeObj = (GameObject)Instantiate (smoke, transform.TransformPoint(transform.position), Quaternion.identity);

I have also tried:

 GameObject smokeObj = (GameObject)Instantiate (smoke, transform.position, Quaternion.identity);

I know that the reason that the smoke is created in to wrong location is due to GUIElements using a different coordinate system than other gameObjects.

How can I create the smoke in the correct location?

This is a 2D project and I am currently using Unity 4.5of6, with windows 8.1.

Thank you for your assistance, if you have any questions please do not hesitate to ask.

The camera class has a bunch of helper functions for translating points to/from “screen points” (in pixels) and “viewport points” (which GUITextures use) and “world points” (in the scene itself).

In particular, it sounds like you might want ViewportToWorldPoint. Be careful to set a z-component for your input, which represents the desired distance away from the camera.

When in doubt, Camera.main is usually the player’s main camera.

Something like this:

Vector3 worldPos = Camera.main.ViewportToWorldPoint(SOME_GUI_POSITION + Vector3.forward);