Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7. // En esta variable configuraremos la velocidad a la que se moverá el objeto
  8. public float Velocidad = 5.0F;
  9. public float AlturaSalto = 10.0F;
  10.  
  11. private bool derecha = false;
  12. private bool izquierda = false;
  13. private bool saltar = false;
  14. private bool habilidad = false;
  15. private bool objeto = false;
  16. private bool jump = false;
  17. public bool grounded;
  18. private Rigidbody2D rb2d;
  19.  
  20. void Start()
  21. {
  22. rb2d = GetComponent<Rigidbody2D>();
  23. }
  24.  
  25. void FixedUpdate()
  26. {
  27. if (derecha)
  28. {
  29. // Movemos el objeto hacia la derecha
  30. this.transform.Translate(Vector2.right * Time.deltaTime * Velocidad);
  31. }
  32.  
  33. if (izquierda)
  34. {
  35. // Movemos el objeto hacia la izquierda
  36. this.transform.Translate(Vector2.left * Time.deltaTime * Velocidad);
  37. }
  38.  
  39. if (saltar && grounded)
  40. {
  41. jump = true;
  42. }
  43.  
  44. if (jump)
  45. {
  46. // Movemos el objeto hacia arriba
  47.  
  48. rb2d.velocity = new Vector2(rb2d.velocity.x, AlturaSalto);
  49. saltar = false;
  50. jump = false;
  51. }
  52.  
  53. if (habilidad)
  54. {
  55.  
  56. }
  57.  
  58. if (objeto)
  59. {
  60.  
  61. }
  62. }
  63.  
  64. /******************** FUNCIONES PÚBLICAS ********************/
  65.  
  66. public void MoverDerecha()
  67. {
  68. derecha = true;
  69. }
  70.  
  71. public void MoverIzqda()
  72. {
  73. izquierda = true;
  74. }
  75.  
  76. public void MoverArriba()
  77. {
  78. saltar = true;
  79. }
  80.  
  81. public void UsarHabilidad()
  82. {
  83. habilidad = true;
  84. }
  85.  
  86. public void Detener()
  87. {
  88. derecha = false;
  89. izquierda = false;
  90. saltar = false;
  91. habilidad = false;
  92. objeto = false;
  93. }
  94.  
  95. public void UsarObjeto()
  96. {
  97. objeto = true;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement