Advertisement
Pohl

Untitled

Oct 9th, 2024
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.82 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Movimiento : MonoBehaviour
  6.  
  7. {
  8.     // Start is called before the first frame update
  9.     void Start()
  10.     {
  11.  
  12.     }
  13.  
  14.     // Update is called once per frame
  15.     void Update()
  16.     {
  17.         float movimientoEnZ = 0f;
  18.         float movimientoEnX = 0f;
  19.         float movimientoEnY = 5f;
  20.  
  21.  
  22.         //Movimiento Personaje WSAD, primero Z y despues X
  23.         // Pero es esta parte es con SHIFT para que vaya 5 veces mas rapido
  24.  
  25.         if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
  26.         {
  27.             print("Tecla W Presionada, Adelante");
  28.             movimientoEnZ = 5f;
  29.  
  30.         }
  31.         else if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.LeftShift))
  32.         {
  33.             print("Tecla S presionada, Atras");
  34.             movimientoEnZ = -5f;
  35.  
  36.         }
  37.  
  38.         if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift))
  39.         {
  40.             print("Tecla D presionada, Derecha");
  41.             movimientoEnX = -5f;
  42.  
  43.  
  44.         }
  45.         else if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift))
  46.         {
  47.             print("Tecla A Presionada, Izquierda");
  48.             movimientoEnX = 5f;
  49.  
  50.         }
  51.  
  52.  
  53.         //Movimiento Personaje WSAD, primero Z y despues X
  54.  
  55.  
  56.         if (Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.LeftShift))
  57.         {
  58.             print("Tecla W Presionada, Adelante");
  59.             movimientoEnZ = 1f;
  60.  
  61.         }
  62.         else if (Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.LeftShift)) {
  63.  
  64.             print("Tecla S presionada, Atras");
  65.             movimientoEnZ = -1f;
  66.  
  67.         }
  68.  
  69.         if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.LeftShift))
  70.         {
  71.             print("Tecla D presionada, Derecha");
  72.             movimientoEnX = -1f;
  73.  
  74.  
  75.         }
  76.         else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.LeftShift))
  77.         {
  78.             print("Tecla A Presionada, Izquierda");
  79.             movimientoEnX = 1f;
  80.  
  81.         }
  82.  
  83.  
  84.         //Espacio, salto
  85.  
  86.  
  87.         if (Input.GetKeyDown(KeyCode.Space) && !Input.GetKey(KeyCode.LeftShift))
  88.         {
  89.             print("Tecla Espacio presionada, Arriba");
  90.             GetComponent<Rigidbody>().AddForce(Vector3.up * movimientoEnY, ForceMode.Impulse);
  91.            
  92.         }
  93.  
  94.         if(Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.LeftShift))
  95.         {
  96.             GetComponent<Rigidbody>().AddForce(Vector3.up * movimientoEnY, ForceMode.Impulse);
  97.             movimientoEnZ += 10f;
  98.             GetComponent<Rigidbody>().AddForce(Vector3.forward * movimientoEnZ, ForceMode.Impulse);
  99.  
  100.         }
  101.  
  102.  
  103.  
  104.         Vector3 movimiento = new Vector3(movimientoEnX, 0f, movimientoEnZ);
  105.  
  106.         GetComponent<Rigidbody>().AddForce(movimiento * 2);
  107.    
  108.     }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement