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 Player : MonoBehaviour {
- public Transform player;
- public float velocidad;
- public float velocidadRotacion;
- public float alturaSalto;
- bool cae = false;
- public bool salta = false;
- float origenSalto;
- float destinoSalto;
- public float velocidadSalto;
- float translacionTemporal;
- // Use this for initialization
- void Start () {
- origenSalto = player.position.y;
- destinoSalto = origenSalto + alturaSalto;
- translacionTemporal = alturaSalto / velocidadSalto;
- }
- // Update is called once per frame
- void Update () {
- //Mov Izquierda
- if (Input.GetKey(KeyCode.A))
- {
- player.Rotate(new Vector3(0f, -velocidadRotacion * Time.deltaTime, 0f));
- }
- //Mov Derecha
- if (Input.GetKey(KeyCode.D))
- {
- player.Rotate(new Vector3(0f, velocidadRotacion * Time.deltaTime, 0f));
- }
- //Mov Frente
- if (Input.GetKey(KeyCode.W))
- {
- player.Translate(Vector3.forward * velocidad * Time.deltaTime);
- }
- //Mov Atras
- if (Input.GetKey(KeyCode.S))
- {
- player.Translate(Vector3.back * velocidad * Time.deltaTime);
- }
- //Salto
- if (cae == false)
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- //Debug.Log("Entró la condición de salto");
- salta = true;
- }
- }
- if (salta)
- {
- cae = true;
- player.Translate(Vector3.up * translacionTemporal );
- translacionTemporal = translacionTemporal / velocidadSalto;
- Debug.Log(translacionTemporal);
- if (player.position.y >= destinoSalto)
- {
- salta = false;
- translacionTemporal = alturaSalto / velocidadSalto;
- Debug.Log(translacionTemporal);
- cae = false;
- }
- }
- }
- void OnCollisionEnter()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement