Movimiento flechas con el teclado Unity
Aqui os enseñare como mover nuestro personaje con las flechas de las teclas del teclado:
Primero creamos las variables de nuestro personaje:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class movimiento : MonoBehaviour { public float velX = 0.1f; public float movX; public float inputX;
Ahora crearemos nuestro movimiento hacia la derecha:
void FixedUpdate () { float inputX = Input.GetAxis("Horizontal"); if (inputX>0) { movX = transform.position.x + (inputX * velX); transform.position = new Vector3 (movX, transform.position.y, 0); transform.localScale = new Vector3(1, 1, 1);
AHora hacemos lo mismo para el movimiento hacia la Izquierda
} if (inputX<0) { movX = transform.position.x + (inputX * velX); transform.position = new Vector3 (movX, transform.position.y, 0); transform.localScale = new Vector3(- 1, 1, 1); } } }
así tendriamos nuestro movimiento derecha he izquierda .
Y aquí les dejo el codigo entero :
using System.Collections; using System.Collections.Generic; using UnityEngine; public class movimiento : MonoBehaviour { public float velX = 0.1f; public float movX; public float inputX; // Use this for initialization void Start () { } void FixedUpdate () { float inputX = Input.GetAxis("Horizontal"); if (inputX>0) { movX = transform.position.x + (inputX * velX); transform.position = new Vector3 (movX, transform.position.y, 0); transform.localScale = new Vector3(1, 1, 1); } if (inputX<0) { movX = transform.position.x + (inputX * velX); transform.position = new Vector3 (movX, transform.position.y, 0); transform.localScale = new Vector3(- 1, 1, 1); } } }
Una vez realizado esto moveriamos nuestro personaje hacia la derecha, izquierda:
gracias! sigue aciendo mas tutoriales !
ello there! This is my firste visite to your blog! bueno are a team of
volunters and estarting a new initiative in a comunity
in the same niche. Your blog provided us valuable information to work on. You
ave done a marvellous job!
hola me gustaria saber como puedo acerlo saltar y agacharse
Nice blog here! Also your website loads up fast!
What web host are you using? Can I get your affiliate link to your host?
I wish my web site loaded up as quickly as yours lol