I have this code, the commented part i want to do once per time, and because i need to put this code in the update function is constantly do the sum every frame, but i just need once per time when the player press the the arrowKeys. i Try to recreate this game: Tero beats PSX Bishi Bashi Special 2 Part 1 - YouTube especially the speedbar. Thanks and sorry if my english suck.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private bool avanzar = false;
private float velocidadAvanza = 15f;
private float sumaPower = 0.1f;
void Start () {
}
void Update () {
Avanzar();
}
void Avanzar()
{
if(Input.GetKeyDown(KeyCode.RightArrow))
{
if(avanzar==false)
{
transform.Translate(Vector3.right * velocidadAvanza * Time.deltaTime);
avanzar = true;
PowerBar.restaPower += sumaPower; // <== Do this only Once
}
}
if(Input.GetKeyDown(KeyCode.LeftArrow))
{
if(avanzar==true)
{
transform.Translate(Vector3.right * velocidadAvanza * Time.deltaTime);
avanzar = false;
PowerBar.restaPower += sumaPower; // <== Do this only Once
}
}
}
}