- Home /
Adding y position?
ok i jsut need to move my camera up a few y positions
example
transform.position.y = transform.position.y +90;
Whats wrong with that? if transform is the camera
Answer by denewbie · Nov 17, 2010 at 09:05 AM
You could try a tralslation instead.
transform.Translate(Vector3.up * 90, Space.World);
The Space.World ensures it moves with respect to world. For local translation just use: transform.Translate(Vector3.up * 90);
Thanks for enlightening me along the way. I always went for the long version (see my answer). It just struck me how much more elegant your method is :)
Answer by Statement · Dec 06, 2010 at 11:31 PM
I assume this is C# code. In C#, you can't modify struct fields on properties directly because properties return a copy of the value. It would make no sense to modify a field on a local copy.
I present two options.
As denewbie says:
transform.Translate(Vector3.up * 90, Space.World);
And the long hand version:
Vector3 position = transform.position;
position.y += 90;
transform.position = position;
You decide what makes the cleanest solution.
Answer by Uriel_96 · Dec 07, 2010 at 12:22 AM
Why you dont easily put
transform.localPosition.y += 90;
O$$anonymous$$, I'm geting confuse, what he wants is this but in C#???
if you need it with C# you only need to see this page http://unity3d.com/support/documentation/ScriptReference/Transform-localPosition.html and change java script to C#
Answer by Eric5h5 · Nov 16, 2010 at 10:53 PM
Nothing is wrong with it, though you could shorten it by writing
transform.position.y += 90;
Cannot modify the return value of 'UnityEngine.Transform.position' because it is not a variable (CS1612)
Does not work in C#
Hi. for C# you cant modify a singe values you have to do it like this:
transform.position = new Vector3(transform.position.x, transform.position.y+90, transform.position.z );
I find it a pain so i just just Translate
You just double posted my comment here aswell and voted me down on the double answer. Isn't that slightly hypocritical? Ah well whatever. As long as it gets an accepted answer somehow. Cba flamewars
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Strategy camera problems. 0 Answers
how to put like a camera on the enemy so he can see you only in a specific angle? 1 Answer
Camera problem 2 Answers
Toggle map/Camera [JS] 1 Answer