- Home /
How to increase an object's animation speed based on the speed of what the player clicks/taps onscreen
Hey guys!
I'm extremely new to Unity and was wondering if anyone could share their knowledge as to how I would go about increasing/decreasing an objects animation speed and it's actual movement speed based on the speed that the player clicks/tap on screen? If no clicking/tapping is detected the object would move on a set default speed.
Example would be: if no clicks/taps are detected player movement speed would be 1 m/s. 3 clicks/taps a second would increase the speed by lets say 2 m/s, while clicking/tapping 5 times a second would increase the speed to 4 m/s and so on.
Answer by OmerDoron · Feb 13, 2017 at 02:06 PM
note that this script will change the overall time scale in your whole project, but I think that will help you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeadHit : MonoBehaviour {
public float speedIncreaseAmount = 0.1f; //you can change that in the inspector.
void Update () {
if (Input.GetButtonDown ("Fire1")) {
Time.timeScale += speedIncreaseAmount; //if player tapped, increase overall timeScale by speedIncreaseAmont.
}
}
Although this works and it's fun to look at the object still needs to decrease speed again if there are no clicks happening and/or if the player clicks very slowly (less than 3 clicks a second).
Think of it as a character walking. If I continuous click at a rate of 3 clicks a second the player character will then Jog and if i stop clicking the player will go back to his/her walking state. If I click more then 3 clicks a second the player will go into a fast running state and if no clicks are detected, the character will slow down into his/her walking state go back and so on.
thanks for the fast response though.
@Derik-Stavast this is my question too. please let us know if you had any Success in this case.
this isn't a good answer because changing the timescale will change the overall time scale in whole project. he's looking for a way to increase the speed of player animation and player obj itself, just like in real world when we decide to run but things and creatures around us stay like the way they were!
Your answer
