Unity Movimiento

Movimiento del personaje en Unity hacia la derecha

Void Update


void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;

 }
 transform.Translate(0.04f, 0, 0);
}

Con  esto conseguiríamos que nuestro personaje  al pulsar la D se mueva hacia la derecha,

y con transform.Translate(0.04, 0,0);

pondríamos la velocidad de nuestro personaje

ahora realizaremos lo mismo para que nuestro personaje se mueva hacia la izquierda


 }

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;

}

 transform.Translate(0.04f, 0, 0);
}

Ahora hacemos lo siguiente:

 

Programacion añadimos el siguiente codigo que marcare en Rojo

 


void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(0.04f, 0, 0);

}

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(-0.04f, 0, 0);

}

if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.C)){
 GetComponent<Animator>().SetBool("correr", false);

        }

    }

}

Añadimos lo marcado en rojo en nuestro codigo ahora por ultimo programamos el salto


}
 if (Input.GetKeyDown(KeyCode.Space)){
 GetComponent<Rigidbody2D>().AddForce(new Vector2(0,salto));

}


 
 }
}

y así quedaria:


void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(0.04f, 0, 0);

}

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(-0.04f, 0, 0);

}

if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.C)){
 GetComponent<Animator>().SetBool("correr", false);

}
 if (Input.GetKeyDown(KeyCode.Space)){
 GetComponent<Rigidbody2D>().AddForce(new Vector2(0,salto));

}


 
 }
}



 

En este video podreis ver todo lo que explicado .

Proximamente intentare crear un juego y colgarlo en la pagina.

Con este programa podra crear juegos, o aplicaciones. para Pc,

colgar Online, y Android. poco a poco os intentare ir enseñando.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movimiento : MonoBehaviour {

public float salto;


 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(0.04f, 0, 0);

}

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(-0.04f, 0, 0);

}

if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.C)){
 GetComponent<Animator>().SetBool("correr", false);

}
 if (Input.GetKeyDown(KeyCode.Space)){
 GetComponent<Rigidbody2D>().AddForce(new Vector2(0,salto));

}


 
 }
}


Un codigo bastante facil de usar y poner en Practica.

Unity movimiento

Movimiento del personaje en Unity hacia la derecha

Void Update


void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;

 }
 transform.Translate(0.04f, 0, 0);
}

Con  esto conseguiríamos que nuestro personaje  al pulsar la D se mueva hacia la derecha,

y con transform.Translate(0.04, 0,0);

pondríamos la velocidad de nuestro personaje

ahora realizaremos lo mismo para que nuestro personaje se mueva hacia la izquierda


 }

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;

}

 transform.Translate(0.04f, 0, 0);
}

Ahora hacemos lo siguiente:

 

Programacion añadimos el siguiente codigo que marcare en Rojo

 


void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(0.04f, 0, 0);

}

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(-0.04f, 0, 0);

}

if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.C)){
 GetComponent<Animator>().SetBool("correr", false);

        }

    }

}

Añadimos lo marcado en rojo en nuestro codigo ahora por ultimo programamos el salto


}
 if (Input.GetKeyDown(KeyCode.Space)){
 GetComponent<Rigidbody2D>().AddForce(new Vector2(0,salto));

}


 
 }
}

y así quedaria:


void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(0.04f, 0, 0);

}

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(-0.04f, 0, 0);

}

if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.C)){
 GetComponent<Animator>().SetBool("correr", false);

}
 if (Input.GetKeyDown(KeyCode.Space)){
 GetComponent<Rigidbody2D>().AddForce(new Vector2(0,salto));

}


 
 }
}



 

En este video podreis ver todo lo que explicado .

Proximamente intentare crear un juego y colgarlo en la pagina.

Con este programa podra crear juegos, o aplicaciones. para Pc,

colgar Online, y Android. poco a poco os intentare ir enseñando.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movimiento : MonoBehaviour {

public float salto;


 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 if (Input.GetKey(KeyCode.B)){
 if (GetComponent<SpriteRenderer>().flipX == true) { 
 GetComponent<SpriteRenderer>().flipX = false;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(0.04f, 0, 0);

}

if (Input.GetKey(KeyCode.C)){
 if (GetComponent<SpriteRenderer>().flipX == false) { 
 GetComponent<SpriteRenderer>().flipX = true;


 }
 GetComponent<Animator>().SetBool("correr", true);
 transform.Translate(-0.04f, 0, 0);

}

if (Input.GetKeyUp(KeyCode.B) || Input.GetKeyUp(KeyCode.C)){
 GetComponent<Animator>().SetBool("correr", false);

}
 if (Input.GetKeyDown(KeyCode.Space)){
 GetComponent<Rigidbody2D>().AddForce(new Vector2(0,salto));

}


 
 }
}

Un comentario

  1. wow, marvelous weblog layout! ow lengthy ave you ever bien runing a

    blog for? you made runing a blog look easy. The entire look

    of your website is magnificent, as wel as the contente material!

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *