- Home /
Storing values from a component
Hey, still a rookie here trying to get use to unity coding.
Well, I am trying to store the x,y,z values of a component and setting my GUI text to display in the top left of that component always. I am having issues and not sure I am typing the right thing in to do it properly. Can someone take a moment and look over it and help me?
#pragma strict
function Start () {
}
var screenOf: Component;
function Update () {
var x: float = screenOf.transform.position.x;
var y: float = screenOf.transform.position.y;
var z: float = screenOf.transform.position.z;
transform.position.x = x;
transform.position.y = y;
transform.position.z = z;
}
I read your question three times and still dont know what you're trying to do.
This however is not allowed:
transform.position.x = x;
transform.position.y = y;
transform.position.z = z;
Answer by Eric5h5 · Jan 02, 2013 at 01:19 AM
A Component type doesn't have any x/y/z values. A Transform component does, but you don't need separate float variables, just use a Vector3. A GUIText object however does not use world space coordinates, but rather it uses normalized viewport coordinates. So perhaps this is what you're after.
Oh... Thank you... I just rememeber what I am trying to access isn't a component! It's an object. Dur... Even new to thing one I should of notice that.. Thanks.
I am making a GUI tied to a camera which is going to display some vars for the user.
Also, thanks for that link. It was exactly what I wanted, and I was attempting to do it like that as well when you re$$anonymous$$ded me I was using a component ins$$anonymous$$d of GameObject.