Keep GameObject on a corner of the screen

var guiCam : GameObject;
var targetPos : Vector3;

function Update () 
{
	transform.localPosition = guiCam.camera.ScreenToViewportPoint(targetPos);
} 

Hi, well, the thing is that I have this script attached to the gameobject that I want to keep on the corner independently of the screen resolution, and the gameobject is a child of my GUI camera (which renders all of my gui stuff), but I can’t get it to work, I adjust the desire position and everything but when I go fullscreen it goes out of the screen, so it’s basically not working. I don’t know what I’m doing wrong. Please help! Thanks in advance.

You have an issue that is solvable by using blender or by using an empty game object. That is, you need the pivot/anchor/origin of the hunger meter to be in the corner you want to anchor. You can do this by moving the pivot to the corner in blender, or by placing an empty game object in the corner and making the hunger meter a child of the empty game object. Then you can use Camera.ViewportToWorldPoint() to position the hunger meter. Note you will need to specify a distance in front of the camera to position the object.

var v3Pos = Vector3(0.0, 1.0, 0.25);
transform.position = gui.camera.ViewportToWorldPoint(v3Pos);

The above lines will place the object in the upper left corner of the screen 0.25 units in front of the camera.