Hello Unity community, I’d like to ask for suggestion on something that has been puzzling me for hours now.
I’m trying to implement a jump foward/back or right/left (lets say 2m from where the character was) in my character controller script; I’m using NGUI and What I want to do is at the click of an NGUI button (so using OnClick) to do the directional jump. I did the set up for the buttons and then went to my player script and added the following function:
public void JumpRight (int RightSpeed)
{
float Xto = transform.position.x + 2.41f;
MoveDirection.y = 10;
while (transform.position.x < Xto)
{
//float move = Time.deltaTime * RightSpeed;
//transform.position = new Vector3(transform.position.x + Amtmo,transform.position.y,transform.position.z);
Vector3 velocityright = Vector3.right * 5 * Time.deltaTime;
transform.Translate (velocityright);
}
}
This makes my character teleport to the position; Usually, one would do translate in update, but since I want this to happen when a button is clicked, I thought the loop would accomplish the ask, But It’s not.
Can I please get some suggestions on how to accomplish this?
Thanks in Advance!!!