- Home /
Translating from game space to view space
I'm trying to overlay a gui element onto the gameobject this script is attached to. But I keep getting an error that states :
Assets/flashing_script.js(16,19): BCE0023: No appropriate version of 'UnityEngine.GUI.Label' for the argument list '(UnityEngine.Rect, float)' was found.
Any help would be wonderful. I'm pretty much a noob at this :).
var timer : float = 3;
var viewportPos : Vector3;
function Update () {
viewportPos = Camera.main.WorldToViewportPoint(transform.position);
}
function OnGUI ()
{
GUI.Label (Rect (viewportPos.x, viewportPos.y, 20.0, 20.0), timer);
}
Comment
Answer by Waz · Jul 14, 2011 at 11:22 PM
Label needs a string, so pass it timer.ToString(), instead of timer.
Well that makes a lot of sense after reexa$$anonymous$$ing the documentation. Thank you for the info.
Answer by Eric5h5 · Jul 14, 2011 at 11:23 PM
GUI.Label only takes strings, so you have to convert "timer" to a string. (Using ToString().) Also, please format your code using the code button.