using System.
Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.SocialPlatforms.Impl;
public class CharacterScript : MonoBehaviour
{
[SerializeField] Rigidbody rb;
[SerializeField] float speed;
[SerializeField] float jumpForce;
[SerializeField] Animator animator;
bool isGameOver;
[SerializeField] GameObject menu;
[SerializeField] TMP_Text score;
float roundScore;
[SerializeField] float points;
bool isShield;
void Start()
{
void Update()
{
if (!isGameOver)
{
roundScore += Time.deltaTime;
score.text = "Score: " + roundScore.ToString("f1");
if (Input.GetKeyDown(KeyCode.A) && transform.position.x > -9)
{
transform.Translate(-9, 0, 0);
}
if (Input.GetKeyDown(KeyCode.D) && transform.position.x < 9)
{
transform.Translate(9, 0, 0);
}
if (Input.GetKeyDown(KeyCode.Space) && rb.velocity.y == 0)
{
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
}
if (rb.velocity.y > 0)
{
animator.SetBool("Jump", true);
}
if (rb.velocity.y == 0)
{
animator.SetBool("Jump", false);
}
}
}
void FixedUpdate()
{
if (!isGameOver)
{
rb.MovePosition(transform.position + transform.forward * speed *
Time.deltaTime);
}
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Obstacle"))
{
if (isShield)
{
Destroy(other.gameObject);
}
else
{
print("llego");
isGameOver = true;
menu.SetActive(true);
}
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Money"))
{
roundScore = roundScore + points;
Destroy(other.gameObject, 0f);
}
if (other.CompareTag("Escudo"))
{
isShield = true;
Destroy(other.gameObject);
Invoke("DesactivateShield", 5f);
}
}
void DesactivateShield()
{
isShield = false;
}
}