If i touch a button, it executes this function:
function move_y(howmuch : int){
if(howmuch > 0 && object.transform.localPosition.y<10)
object.transform.Translate(Vector3.up, Space.World);
if(howmuch < 0 && object.transform.localPosition.y>0)
object.transform.Translate(Vector3.down, Space.World);
}
The problem is, that the object is not moving only on the Y axis, but on X and Z axis too and slightly rotates on the Y axis.
What can be the problem?
A few issues I see off the bat:
you probably don’t want localPosition, try object.transform.position.y
if you just want to go straight up and down, you could say:
object.transform.position.y += howMuch;
if you want smooth movement though, better to use something like:
object.transform.position.y = Mathf.Lerp(object.transform.position.y, howMuch);
this would of course need to be called continuously, so maybe get that part into the update function.
maybe could be that physics are affecting the object, if it has a rigidbody
edit:
the easiest way I can think of to accomplish what you seem to want:
function Update()
{
if(Input.GetKey("Fire1") && object.transform.localPosition.y<10)
object.transform.position.y = Mathf.Lerp(object.transform.position.y, 10,Time.deltaTime);
if(Input.GetKey("Fire2") && object.transform.localPosition.y>0)
object.transform.position.y = Mathf.Lerp(object.transform.position.y, 0,Time.deltaTime);
}