Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- using UnityEngine.UI;
- public class JugadorController : MonoBehaviour
- {
- public float velocidadAdelante;
- public float velocidadLateral = 20.0f;
- public float[] posiciones;
- public int posActual = 1;
- [Range(0,1)]
- public float interpolacion;
- public GameObject PanelGameOver;
- public TMP_Text puntosUI;
- public bool estaJugando = true;
- public int puntos = 0;
- private Rigidbody rb;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- private void Update()
- {
- if (estaJugando)
- {
- if (transform.position.x != posiciones[posActual])
- {
- float nuevaPosicionX = Mathf.Lerp(transform.position.x, posiciones[posActual], interpolacion);
- transform.position = new Vector3(nuevaPosicionX, transform.position.y, transform.position.z);
- }
- if (Input.GetKeyDown("left"))
- {
- if (posActual > 0)
- {
- posActual--;
- }
- }
- if (Input.GetKeyDown("right"))
- {
- if (posActual < posiciones.Length - 1)
- {
- posActual++;
- }
- }
- }
- }
- void FixedUpdate()
- {
- if(estaJugando) {
- Vector3 movimiento = new Vector3(0.0f, 0.0f, velocidadAdelante);
- rb.AddForce(movimiento);
- if (Input.GetButtonDown("Fire1"))
- {
- rb.AddForce(0.0f, 300f, 0.0f);
- }
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- if (collision.gameObject.tag == "Obstaculo")
- {
- // Aca mostramos el cartel
- PanelGameOver.SetActive(true);
- estaJugando = false;
- GetComponent<Rigidbody>().AddForce(0.0f, 600.0f, 700.0f);
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if(other.gameObject.tag == "Moneda")
- {
- puntos++;
- puntosUI.text = puntos.ToString();
- Destroy(other.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement