- Home /
Unity 3D: How to make the gameobject speed increase continuously on tapping quickly?
so I am trying to achieve this feat of increasing my game object speed increase if I start tapping continually and then stop and get back to normal when I start tapping slowly. I am attaching a video below which have the cube and I have a sphere and I want to have exactly this effect. I am kinda new to unity. I appreciate any help that I cam get thanks.
VIDEO -- https://drive.google.com/file/d/1WzvsY47RZgmiGuoY1pe6l1_U19EeP2To/view?usp=drivesdk
Answer by Llama_w_2Ls · Jul 28, 2020 at 12:10 PM
float FastPressTime = 0.5f;
public Rigidbody playerRb;
float increaseSpeedAmount = 50f;
private void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(TimeBetweenPresses());
}
}
IEnumerator TimeBetweenPresses()
{
float Counter = 0;
Start:
yield return new WaitForSeconds(0.1f);
Counter += 0.1f;
if (Input.GetMouseButtonDown(0) && Counter <= FastPressTime)
{
playerRb.velocity = new Vector3(playerRb.velocity.x, playerRb.velocity.y, playerRb.velocity.z + increaseSpeedAmount);
}
else if (Input.GetMouseButtonDown(0) && Counter > FastPressTime)
{
playerRb.velocity = new Vector3(playerRb.velocity.x, playerRb.velocity.y, playerRb.velocity.z - increaseSpeedAmount);
}
else
{
goto Start;
}
}
Something along these lines.
Your answer
Follow this Question
Related Questions
Unity 3D: how to make the game object increase the speed on continually tapping? 0 Answers
Unity 3D: How to make the game object speed increase in tapping continually? 0 Answers
[C#] How to make this code toggleable 3 Answers
How do I make a crouch script unity 3d 1 Answer
How to debug the object position in the grid of objects? 0 Answers