Hi,
I'm trying to get the position of an object with..
var objectpos : Vector3 = transform.position;
but I get the error "Argument Exception: You are not allowed to call get_transform when declaring a variable. Move it to the line after without a variable decleration."
I dont really understand how to solve this, can anyone help?
thanks
Also, depending on what you're doing, you may want to declare the objectpos variable as an open variable in your quote, then make the objectpos = transform.position; code in the update() function if you want it to be current, or in the Start() function if you just want it to be the original object position.
– anon67649707Thanks mate, thats nailed it. appreciate it.
– keefusThats great, thanks for the additional info. Just as an aside, would you happen to know the correct syntax for getting the position of a different gameobject to the one with the script attatched? another simple thing I'm struggling with. Thanks in advance.
– keefusYou need to declare the other gameobject, check http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.html . I'd do something like var otherObject : GameObject;, then otherObject = GameObject.Find("name"); and then you can use otherObject.transform.position to get its position
– anon67649707Thanks very much for helping me out. I am however having an issue with the line "otherObject.transform.position" I get the error "Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.GameObject'"
– keefus