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 ControladorFPV : MonoBehaviour {
- //Variables de movimiento
- // Transform de la cámara
- Transform tr;
- //Velocidad de Movimiento de la cámara
- public float vel;
- //Sensibilidad vertical del Mouse
- [SerializeField]private float velVertical;
- //Sensibilidad Horizontal de Mouse
- [SerializeField]private float velHorizontal;
- //Variables de abducción
- //Ver si está flotando
- public bool flotando;
- //variable de RigidBody del objeto
- private Rigidbody rb;
- public float velocidadAbduccion;
- public float alturaAbduccion;
- //Almacena la posición actual del objeto
- private float posActual;
- private float posDestino;
- private float posInicial;
- //Cambio de color
- Color[] colores = new Color[] { Color.white, Color.red, Color.green, Color.blue };
- private int currentColor, lenght;
- MeshRenderer rend;
- // Use this for initialization
- void Start () {
- tr = GetComponent<Transform>();
- rb = GetComponent<Rigidbody>();
- posInicial = 0f;
- currentColor = 0;
- lenght = colores.Length;
- //rend.material.color = colores[currentColor];
- rend = GetComponent<MeshRenderer>();
- }
- // Update is called once per frame
- void Update()
- {
- //Si no flota puede moverse
- if (!flotando)
- {
- //Translada el objeto en Z cuando se presiona la tecla W
- if (Input.GetKey(KeyCode.W))
- {
- tr.Translate(new Vector3(0f, 0f, vel * Time.deltaTime));
- }
- //Translada el objeto en Z cuando se presiona la tecla S
- if (Input.GetKey(KeyCode.S))
- {
- tr.Translate(new Vector3(0f, 0f, -vel * Time.deltaTime));
- }
- //Translada el objeto en X cuando se presiona la tecla D
- if (Input.GetKey(KeyCode.D))
- {
- tr.Translate(new Vector3(vel * Time.deltaTime, 0f, 0f));
- }
- //Translada el objeto en X cuando se presiona la tecla A
- if (Input.GetKey(KeyCode.A))
- {
- tr.Translate(new Vector3(-vel * Time.deltaTime, 0f, 0f));
- }
- }
- //Rota el objeto en el eje X para mirar arriba o abajo en relación al mouse
- float v = velVertical * Input.GetAxis("Mouse Y");
- float h = velHorizontal * Input.GetAxis("Mouse X");
- tr.Rotate(-v, h, 0f);
- //Controla la abducción usando la tecla Space
- if (!flotando && Input.GetKeyDown(KeyCode.Space))
- {
- flotando = true;
- rb.useGravity = false;
- posDestino = tr.position.y + alturaAbduccion;
- }
- if (flotando)
- {
- flotando = Abduccion(velocidadAbduccion, alturaAbduccion, posDestino);
- }
- if (Input.GetMouseButtonDown(0))
- {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray,out hit, 100))
- {
- currentColor = (currentColor + 1) % lenght;
- //rend.material.color = colores[currentColor];
- rend.material.color = colores[currentColor];
- }
- }
- /*if (Input.GetMouseButtonDown(0))
- {
- currentColor = (currentColor + 1) % lenght;
- rend.material.color = colores[currentColor];
- }*/
- }
- bool Abduccion(float vA, float aA, float pD)
- {
- tr.Translate(new Vector3(0f,vA * Time.deltaTime , 0f));
- if (tr.position.y >= pD )
- {
- rb.useGravity = true;
- return false;
- }
- else
- {
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement