Rapid tapping to move?
I am trying to make a game where you rapid press a button, and the faster you press it, the faster the character goes. The speed also decreases with time (so that if you don't press anything, the character will slow down). I tried it with the code below, but the character wouldn't move at all on the screen...is there a better way to implement this?
using UnityEngine; using System.Collections;
public class DogRunning : MonoBehaviour {
 float Press1=0;
 float Press2=0;
 float timeBetweenPresses=0;
 int count = 0;
 float speed = 0;
 float speedDec = 0.1f;
 // Use this for initialization
 void Start () 
 {
     
 }
 
 // Update is called once per frame
 void Update ()
 {    
     if (speed >= 0.1) {
         speed -= Time.deltaTime * speedDec;
     }
     if (Input.GetKeyUp (KeyCode.W) && count == 0) {
         Press1 = Time.time;
         count++;
     }
     if (Input.GetKeyUp (KeyCode.W) && count == 1){
         Press2 = Time.time;
         timeBetweenPresses = Press2 - Press1;
         Press1 = 0;
         count++;
     }
     if (Input.GetKeyUp(KeyCode.W) && count == 2){
         Press1 = Time.time;
         timeBetweenPresses = Press1 - Press2;
         Press2 = 0;
         count--;
     }
     if (timeBetweenPresses != 0) {
         speed += 1 / timeBetweenPresses;
         transform.Translate (Vector3.up * speed * Time.deltaTime);
     }
 }
 
               }
I'm not really going to answer this one, but I'm surprised you haven't needed to use Input.Get$$anonymous$$eyDown. $$anonymous$$aybe that's the issue.
Your answer
 
             Follow this Question
Related Questions
Time delay enemy respawn 3 Answers
Delay in time 0 Answers
Change Time.scale only on specific objects 1 Answer
Question about timing . 0 Answers
Displaying C# Int Value to GUI 2 Answers