Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Movimiento : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- float movimientoEnZ = 0f;
- float movimientoEnX = 0f;
- float movimientoEnY = 5f;
- //Movimiento Personaje WSAD, primero Z y despues X
- // Pero es esta parte es con SHIFT para que vaya 5 veces mas rapido
- if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla W Presionada, Adelante");
- movimientoEnZ = 5f;
- }
- else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla S presionada, Atras");
- movimientoEnZ = -5f;
- }
- if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla D presionada, Derecha");
- movimientoEnX = -5f;
- }
- else if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla A Presionada, Izquierda");
- movimientoEnX = 5f;
- }
- //Movimiento Personaje WSAD, primero Z y despues X
- if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla W Presionada, Adelante");
- movimientoEnZ = 1f;
- }
- else if (Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.LeftShift)) {
- print("Tecla S presionada, Atras");
- movimientoEnZ = -1f;
- }
- if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla D presionada, Derecha");
- movimientoEnX = -1f;
- }
- else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla A Presionada, Izquierda");
- movimientoEnX = 1f;
- }
- //Espacio, salto
- if (Input.GetKeyDown(KeyCode.Space) && !Input.GetKey(KeyCode.LeftShift))
- {
- print("Tecla Espacio presionada, Arriba");
- GetComponent<Rigidbody>().AddForce(Vector3.up * movimientoEnY, ForceMode.Impulse);
- }
- if(Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.LeftShift))
- {
- GetComponent<Rigidbody>().AddForce(Vector3.up * movimientoEnY, ForceMode.Impulse);
- movimientoEnZ += 10f;
- GetComponent<Rigidbody>().AddForce(Vector3.forward * movimientoEnZ, ForceMode.Impulse);
- }
- Vector3 movimiento = new Vector3(movimientoEnX, 0f, movimientoEnZ);
- GetComponent<Rigidbody>().AddForce(movimiento * 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement