Problem with moving (456441)

I have this code
function Update () {

var horiz : float = Input.GetAxis(“HLeft”);

var post : float = 0;

if(Input.GetButtonUp(“HLeft”))

{

transform.Translate(Vector3(horiz,0,0));

transform.position.x = Mathf.Clamp(transform.position.x, -2.046169, 1.93117);

}

}

My first problem is, when i click on a/d/left/right = HLeft, then it moves only when u click
My secound problem is, that i want the object to move to 3 posistion

First position is where x = 0,
the secound is where x = -2.046169
And the third is wher ex = 1.93117);

HOw do i do that?

op

Input.GetButtonUp is only called on the single frame during which you released a button, so anything inside that condition is only called on that frame.

You might want to try using Input.GetButton instead, or just check if your variable “horiz” is != 0.

I’m not sure I understand the second problem.

Thanks for the answer to question 1.

About question 2.

I want the object, to move side ways. so it only can move in specifics position.
Do U get it?

Op

up!

Try not to add useless responses to your posts just to make your question the most recent - you’ll get few responses that way as most people find it annoying, including myself.

That said…

I still don’t quite understand what you’re trying to do, but it sounds like you want the object to switch between 3 different positions when you press the left key or ‘a’. If that’s the case, transform.Translate is probably not what you want to do. You most likely need to either create 3 variables (one for each position) and switch transform.position.x between them, or create a builtin array of floats an cycle through that.