- Home /
How i can make a running button?
I've been trying to create a button that increases the player's speed depending on the speed with which this button is pressed.
but I can not get the result I need. Speed does not decrease correctly if I press the button more slowly, and achievement not make it more difficult to increase as the value becomes higher
here part of the code:
public var forwardSpeed : float = 2;
public function Velocity()
{
if ("morevelocity"){ //If the button is pressed
if(forwardSpeed<25){
forwardSpeed += 1 / forwardSpeed;
}
}
}
function Update()
{
if (forwardSpeed>1.5){
forwardSpeed -= 0.5 * Time.deltaTime * forwardSpeed;
}
var movement = Vector3.right * forwardSpeed * 1;
i need some help, i try some much.
Your UpperLimit =25 ,lowerLimit=1.5 and default=2f; Your update condition will be always true . When ever you will press the speedup btn ur decreasespeed will be also called.
in fact, I need the player to press the button as quickly as possible or else the speed will decrease.
plzz give some data..i cant understand " Speed does not decrease correctly" . so that i can help. By how much amount it decrease...stuff like tat
I appreciate that you try to solve my problem, and I apologize if I can not express myself properly. $$anonymous$$y problem is that when you reach 25 speed, this does not require you to press quickly, but slowly press speed is maintained or even increases, so does not require the player to press quickly.
float fv=2f; Transform _transform; // Use this for initialization void Start () { _transform = this.transform;
}
// Update is called once per frame
void Update () {
if (fv > 1.5f) {
fv -= 0.5f * Time.deltaTime * fv;
_transform.position = new Vector3 (fv,_transform.position.y,_transform.position.z);
}
if (Input.Get$$anonymous$$ouseButtonDown (0)) {
if(fv<25)
fv += 2f;
}
}