Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7.  
  8. public Transform player;
  9.  
  10. public float velocidad;
  11.  
  12. public float velocidadRotacion;
  13.  
  14. public float alturaSalto;
  15.  
  16. bool cae = false;
  17.  
  18. public bool salta = false;
  19.  
  20. float origenSalto;
  21.  
  22. float destinoSalto;
  23.  
  24. public float velocidadSalto;
  25.  
  26. float translacionTemporal;
  27.  
  28.  
  29.  
  30. // Use this for initialization
  31. void Start () {
  32.  
  33. origenSalto = player.position.y;
  34. destinoSalto = origenSalto + alturaSalto;
  35. translacionTemporal = alturaSalto / velocidadSalto;
  36.  
  37. }
  38.  
  39. // Update is called once per frame
  40. void Update () {
  41.  
  42.  
  43.  
  44. //Mov Izquierda
  45. if (Input.GetKey(KeyCode.A))
  46. {
  47. player.Rotate(new Vector3(0f, -velocidadRotacion * Time.deltaTime, 0f));
  48. }
  49.  
  50. //Mov Derecha
  51. if (Input.GetKey(KeyCode.D))
  52. {
  53.  
  54. player.Rotate(new Vector3(0f, velocidadRotacion * Time.deltaTime, 0f));
  55. }
  56.  
  57. //Mov Frente
  58. if (Input.GetKey(KeyCode.W))
  59. {
  60. player.Translate(Vector3.forward * velocidad * Time.deltaTime);
  61. }
  62.  
  63. //Mov Atras
  64. if (Input.GetKey(KeyCode.S))
  65. {
  66. player.Translate(Vector3.back * velocidad * Time.deltaTime);
  67. }
  68.  
  69. //Salto
  70. if (cae == false)
  71. {
  72. if (Input.GetKeyDown(KeyCode.Space))
  73. {
  74. //Debug.Log("Entró la condición de salto");
  75. salta = true;
  76.  
  77. }
  78.  
  79. }
  80.  
  81. if (salta)
  82. {
  83. cae = true;
  84.  
  85. player.Translate(Vector3.up * translacionTemporal );
  86.  
  87. translacionTemporal = translacionTemporal / velocidadSalto;
  88. Debug.Log(translacionTemporal);
  89. if (player.position.y >= destinoSalto)
  90. {
  91. salta = false;
  92. translacionTemporal = alturaSalto / velocidadSalto;
  93. Debug.Log(translacionTemporal);
  94. cae = false;
  95. }
  96.  
  97.  
  98.  
  99. }
  100.  
  101.  
  102. }
  103.  
  104. void OnCollisionEnter()
  105. {
  106.  
  107. }
  108.  
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement