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 PlayerController : MonoBehaviour {
- // En esta variable configuraremos la velocidad a la que se moverá el objeto
- public float Velocidad = 5.0F;
- public float AlturaSalto = 10.0F;
- private bool derecha = false;
- private bool izquierda = false;
- private bool saltar = false;
- private bool habilidad = false;
- private bool objeto = false;
- private bool jump = false;
- public bool grounded;
- private Rigidbody2D rb2d;
- void Start()
- {
- rb2d = GetComponent<Rigidbody2D>();
- }
- void FixedUpdate()
- {
- if (derecha)
- {
- // Movemos el objeto hacia la derecha
- this.transform.Translate(Vector2.right * Time.deltaTime * Velocidad);
- }
- if (izquierda)
- {
- // Movemos el objeto hacia la izquierda
- this.transform.Translate(Vector2.left * Time.deltaTime * Velocidad);
- }
- if (saltar && grounded)
- {
- jump = true;
- }
- if (jump)
- {
- // Movemos el objeto hacia arriba
- rb2d.velocity = new Vector2(rb2d.velocity.x, AlturaSalto);
- saltar = false;
- jump = false;
- }
- if (habilidad)
- {
- }
- if (objeto)
- {
- }
- }
- /******************** FUNCIONES PÚBLICAS ********************/
- public void MoverDerecha()
- {
- derecha = true;
- }
- public void MoverIzqda()
- {
- izquierda = true;
- }
- public void MoverArriba()
- {
- saltar = true;
- }
- public void UsarHabilidad()
- {
- habilidad = true;
- }
- public void Detener()
- {
- derecha = false;
- izquierda = false;
- saltar = false;
- habilidad = false;
- objeto = false;
- }
- public void UsarObjeto()
- {
- objeto = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement