I searched it but couldn't find the complete solution to this. I am new to Unity so if you could provide with the coding then it would be really helpful. I want to jump and touch the screen and do a big jump when holding the touch.
Here's the sample code of what i am trying :
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
// Handle finger movements based on TouchPhase
switch (touch.phase)
{
//When a touch has first been detected, change the message and record the starting position
case TouchPhase.Began:
// Record initial touch position.
if (onGround)
{
rb.velocity = new Vector2(rb.velocity.x, jump);
}
startTime = Time.time;
break;
case TouchPhase.Ended:
// Report that the touch has ended when it ends
realTime = Time.time - startTime;
Debug.Log(realTime);
if (realTime > 1.0f)
{
rb.velocity = new Vector2(rb.velocity.x, bigjump);
}
break;
}
}
I also am confused if I should use velocity or AddForce to jump, and why?
↧