Hola amigos he hecho este script pero la verdad es que no me gusta como me ha quedado. Tiene que haber una forma mas sencilla pero no la veo
using UnityEngine;La P en wP sP... es de Pressed y la T de Time El script lo que hace es que cuando pulsas avanzas y si dejas pulsado avanza mas rapido... Si mal no recuerdo en pokemon se usaba algo parecido para que os hagais una idea jeje
using System.Collections;
public class PlayerController : MonoBehaviour {
private bool wP;
private bool sP;
private bool aP;
private bool dP;
private float wT;
private float sT;
private float aT;
private float dT;
void Update () {
if(Input.GetKeyDown(KeyCode.W)){
transform.position += Vector3.up * 0.5f;
wP = true;
}
if(Input.GetKeyDown(KeyCode.S)){
transform.position += Vector3.down * 0.5f;
sP = true;
}
if(Input.GetKeyDown(KeyCode.A)){
transform.position += Vector3.left * 0.5f;
aP = true;
}
if(Input.GetKeyDown(KeyCode.D)){
transform.position += Vector3.right * 0.5f;
dP = true;
}
if(Input.GetKeyUp(KeyCode.W)) { wP = false; wT = 0; }
if(Input.GetKeyUp(KeyCode.S)) { sP = false; sT = 0; }
if(Input.GetKeyUp(KeyCode.A)) { aP = false; aT = 0; }
if(Input.GetKeyUp(KeyCode.D)) { dP = false; dT = 0; }
if(wP){
wT += Time.deltaTime;
if(wT >= 0.5f) { transform.position += Vector3.up * 0.5f; wT = 0.4f; }
}
if(sP){
sT += Time.deltaTime;
if(sT >= 0.5f) { transform.position += Vector3.down * 0.5f; sT = 0.4f; }
}
if(aP){
aT += Time.deltaTime;
if(aT >= 0.5f) { transform.position += Vector3.left * 0.5f; aT = 0.4f; }
}
if(dP){
dT += Time.deltaTime;
if(dT >= 0.5f) { transform.position += Vector3.right * 0.5f; dT = 0.4f; }
}
}
}