- Home /
Quick Question About UnityScript
Is there an easier way to say this?
Vector3(transform.position.x,transform.position.y,transform.position.z-.5)
thanks!
Answer by AlucardJay · Mar 26, 2013 at 04:27 AM
in uJS :
var pos : Vector3 = transform.position;
pos = pos + Vector3( 0, 0, -0.5 );
or :
var pos : Vector3 = transform.position;
pos += Vector3( 0, 0, -0.5 );
or :
var newPos : Vector3 = transform.position + Vector3( 0, 0, -0.5 );
in C# :
Vector3 pos = transform.position;
pos = pos + new Vector3( 0, 0, -0.5 );
as I don't use C#, I am not sure if you can shorten that line to
pos += new Vector3( 0, 0, -0.5 );
but try it out.
or something else to try (this is probably the one you are after) :
Vector3 newPos = transform.position + new Vector3( 0, 0, -0.5 );
Edit : so I fail for not reading the title and the question correctly ! Have updated my answer, sorry (still waking up).
Answer by fabio1955 · Mar 25, 2013 at 10:37 PM
For doing what? Probably you can just use transform.position because this is already a Vector3 object.
i would like to have transform.position, just -.5 in the z...
In C# the best way of doing that is to do transform.position -= Vector3.forward * 0.5 but as fabio1955 says that's not a problem in Unity Script.
Answer by ExpiredIndexCard · Mar 25, 2013 at 11:14 PM
Actually I don't think so. Maybe you can store those values inside a Transform variable. It would make that one line shorter but you would still spend the time writing the variables. Those are your only options sorry about that!
Answer by Bluestrike · Mar 26, 2013 at 07:40 AM
It depends on what you are trying to do:
Move your object 0.5 units on the negative Z axis:
transform.position.z -= .5;
Perhaps you need to do this on its local axis again depending on what your goal is:
transform.localPosition.z -= .5;
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
AI using Javascript 1 Answer
Flipping textures 0 Answers