x


C#: Change transform.position in code

I'm currently trying to replace some animations I was never that happy with (built in Unity) with iTweens... I want to take the gameObject's transform.position and change it a bit, and then save that as a new transform.

But I keep running into "error CS0119: Expression denotes a variable', where amethod group' was expected"

It hits on line 23 in my code, which is completely blank, so I suspect it means where DrawerOutPos.position = tempvect();

Anyway... here's my code:

void Start () { 

DrawerInPos = gameObject.transform; Vector3 tempvect = new Vector3(); tempvect.x = gameObject.transform.position.x; tempvect.y = gameObject.transform.position.y+0.4f; tempvect.z = gameObject.transform.position.z; DrawerOutPos.position = tempvect(); }

more ▼

asked Jul 03 '12 at 08:35 PM

DaveMatney gravatar image

DaveMatney
31 3 4 5

I swear I used to be able to post code properly...

Jul 03 '12 at 08:41 PM DaveMatney
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Try that:

Vector3 tempvect = new Vector3(gameObject.transform.position.x, transform.position.y+0.4f, gameObject.transform.position.z);
DrawerOutPos.position = tempvect;
more ▼

answered Jul 03 '12 at 08:37 PM

Luci85 gravatar image

Luci85
143 6 14 16

INullReferenceException UnityEngine.Transform.set_position (Vector3 value) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/UnityEngineTransform.cs:20) DrawerAnims.Start () (at Assets/Scripts/DrawerAnims.cs:20)

Line 20 is where "DrawerOutPos.position = tempvect;" is falling.

Jul 03 '12 at 08:40 PM DaveMatney
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4143
x1276
x574

asked: Jul 03 '12 at 08:35 PM

Seen: 2277 times

Last Updated: Jul 03 '12 at 08:41 PM