Advertisement
Guest User

Untitled

a guest
Dec 6th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ControladorFPV : MonoBehaviour {
  6.  
  7.  
  8. //Variables de movimiento
  9. // Transform de la cámara
  10. Transform tr;
  11. //Velocidad de Movimiento de la cámara
  12. public float vel;
  13. //Sensibilidad vertical del Mouse
  14. [SerializeField]private float velVertical;
  15. //Sensibilidad Horizontal de Mouse
  16. [SerializeField]private float velHorizontal;
  17.  
  18. //Variables de abducción
  19. //Ver si está flotando
  20. public bool flotando;
  21. //variable de RigidBody del objeto
  22. private Rigidbody rb;
  23. public float velocidadAbduccion;
  24. public float alturaAbduccion;
  25. //Almacena la posición actual del objeto
  26. private float posActual;
  27. private float posDestino;
  28. private float posInicial;
  29.  
  30.  
  31. //Cambio de color
  32.  
  33. Color[] colores = new Color[] { Color.white, Color.red, Color.green, Color.blue };
  34. private int currentColor, lenght;
  35. MeshRenderer rend;
  36.  
  37. // Use this for initialization
  38. void Start () {
  39.  
  40. tr = GetComponent<Transform>();
  41. rb = GetComponent<Rigidbody>();
  42. posInicial = 0f;
  43.  
  44. currentColor = 0;
  45. lenght = colores.Length;
  46. //rend.material.color = colores[currentColor];
  47. rend = GetComponent<MeshRenderer>();
  48.  
  49.  
  50. }
  51.  
  52. // Update is called once per frame
  53. void Update()
  54. {
  55.  
  56. //Si no flota puede moverse
  57. if (!flotando)
  58. {
  59.  
  60. //Translada el objeto en Z cuando se presiona la tecla W
  61. if (Input.GetKey(KeyCode.W))
  62. {
  63.  
  64. tr.Translate(new Vector3(0f, 0f, vel * Time.deltaTime));
  65.  
  66. }
  67.  
  68.  
  69. //Translada el objeto en Z cuando se presiona la tecla S
  70. if (Input.GetKey(KeyCode.S))
  71. {
  72.  
  73. tr.Translate(new Vector3(0f, 0f, -vel * Time.deltaTime));
  74.  
  75. }
  76.  
  77.  
  78. //Translada el objeto en X cuando se presiona la tecla D
  79. if (Input.GetKey(KeyCode.D))
  80. {
  81.  
  82. tr.Translate(new Vector3(vel * Time.deltaTime, 0f, 0f));
  83.  
  84. }
  85.  
  86. //Translada el objeto en X cuando se presiona la tecla A
  87. if (Input.GetKey(KeyCode.A))
  88. {
  89.  
  90. tr.Translate(new Vector3(-vel * Time.deltaTime, 0f, 0f));
  91.  
  92. }
  93.  
  94. }
  95.  
  96.  
  97. //Rota el objeto en el eje X para mirar arriba o abajo en relación al mouse
  98.  
  99. float v = velVertical * Input.GetAxis("Mouse Y");
  100. float h = velHorizontal * Input.GetAxis("Mouse X");
  101. tr.Rotate(-v, h, 0f);
  102.  
  103. //Controla la abducción usando la tecla Space
  104. if (!flotando && Input.GetKeyDown(KeyCode.Space))
  105. {
  106. flotando = true;
  107. rb.useGravity = false;
  108. posDestino = tr.position.y + alturaAbduccion;
  109. }
  110.  
  111. if (flotando)
  112. {
  113.  
  114.  
  115. flotando = Abduccion(velocidadAbduccion, alturaAbduccion, posDestino);
  116. }
  117.  
  118.  
  119. if (Input.GetMouseButtonDown(0))
  120. {
  121. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  122. RaycastHit hit;
  123.  
  124. if (Physics.Raycast(ray,out hit, 100))
  125. {
  126. currentColor = (currentColor + 1) % lenght;
  127. //rend.material.color = colores[currentColor];
  128. rend.material.color = colores[currentColor];
  129.  
  130. }
  131. }
  132.  
  133. /*if (Input.GetMouseButtonDown(0))
  134. {
  135.  
  136. currentColor = (currentColor + 1) % lenght;
  137. rend.material.color = colores[currentColor];
  138.  
  139. }*/
  140.  
  141. }
  142. bool Abduccion(float vA, float aA, float pD)
  143. {
  144.  
  145. tr.Translate(new Vector3(0f,vA * Time.deltaTime , 0f));
  146. if (tr.position.y >= pD )
  147. {
  148. rb.useGravity = true;
  149. return false;
  150. }
  151.  
  152. else
  153. {
  154. return true;
  155. }
  156. }
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement