0% found this document useful (0 votes)
6 views2 pages

CharacterController

CharacterController

Uploaded by

felipe.zuleta1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

CharacterController

CharacterController

Uploaded by

felipe.zuleta1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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;
}
}

You might also like