0% found this document useful (0 votes)
61 views3 pages

Escuela Superior Politécnica de Chimborazo: Facultad: Facultad de Informática Y Electrónica

The document describes code for a 2D platformer game created in Unity. It includes a GameManager script that controls the game loop and spawns obstacles. It also includes a Jugador (player) script that controls player movement and jumping via rigidbody physics and detects collisions with obstacles or the ground. The game has a main menu, game over menu, and allows restarting a scene via buttons.

Uploaded by

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

Escuela Superior Politécnica de Chimborazo: Facultad: Facultad de Informática Y Electrónica

The document describes code for a 2D platformer game created in Unity. It includes a GameManager script that controls the game loop and spawns obstacles. It also includes a Jugador (player) script that controls player movement and jumping via rigidbody physics and detects collisions with obstacles or the ground. The game has a main menu, game over menu, and allows restarting a scene via buttons.

Uploaded by

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

ESCUELA SUPERIOR POLITÉCNICA DE

CHIMBORAZO

FACULTAD: FACULTAD DE INFORMÁTICA Y ELECTRÓNICA


CARRERA: SOFTWARE

ESTUDIANTE: BYRON JAVIER LUCERO CÓDIGO: 6995


SISTEMAS MULTIMEDIA Y
ASIGNATURA: PAO: NOVENO
GAMIFICACIÓN
PERIODO
ABRIL – SEPTIEMBRE 2021
ACADÉMICO:

Enlace Video

https://liveespochedu-
my.sharepoint.com/personal/byron_lucero_espoch_edu_ec/_layouts/15/onedrive.aspx?id=%
2Fpersonal%2Fbyron%5Flucero%5Fespoch%5Fedu%5Fec%2FDocuments%2FJuego%5FJavi%5F
Unity%2Emp4&parent=%2Fpersonal%2Fbyron%5Flucero%5Fespoch%5Fedu%5Fec%2FDocume
nts&originalPath=aHR0cHM6Ly9saXZlZXNwb2NoZWR1LW15LnNoYXJlcG9pbnQuY29tLzp2Oi9n
L3BlcnNvbmFsL2J5cm9uX2x1Y2Vyb19lc3BvY2hfZWR1X2VjL0VZS3ZyR2dfSktwUHVWb1lINjJad0
RvQjJTV3pldmJhMU51aWdfeXVXWEdCdnc%5FcnRpbWU9bDlMWjVUTWgyVWc

Codificación

 GameManager

using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Resources;
using System.Threading;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour


{
public GameObject menuPrincipal;
public GameObject menuGameOver;

public float velocidad = 2;


public GameObject col;
public Renderer fondo;
public GameObject piedra1;
public GameObject piedra2;
public bool gameOver = false;
public bool start = false;

public List<GameObject> cols;


public List<GameObject> obstaculos;
ESCUELA SUPERIOR POLITÉCNICA DE
CHIMBORAZO

// Start is called before the first frame update


void Start()
{
///Crear Mapa
for(int i=0; i<21;i++)
{
cols.Add( Instantiate(col, new Vector2(-11 + i,-3),Quaternion.identity));
}

//Crear Piedra
obstaculos.Add(Instantiate(piedra1, new Vector2(12, -2), Quaternion.identity));
obstaculos.Add(Instantiate(piedra2, new Vector2(16, -2), Quaternion.identity));
}

// Update is called once per frame


void Update()
{
if (start == false)
{
if (Input.GetKeyDown(KeyCode.X))
{
start = true;
}
}

if (start == true && gameOver == true)


{
menuGameOver.SetActive(true);

if (Input.GetKeyDown(KeyCode.X))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
if ( start == true && gameOver == false)
{
menuPrincipal.SetActive(false);

fondo.material.mainTextureOffset = fondo.material.mainTextureOffset + new Vector2(0.02f, 0) *


Time.deltaTime;

//Mover Mapa
for (int i = 0; i < cols.Count; i++)
{
if (cols[i].transform.position.x <= -10)
{
cols[i].transform.position = new Vector3(10, -3, 0);
}
cols[i].transform.position = cols[i].transform.position + new Vector3(-1, 0, 0) * Time.deltaTime *
velocidad;
}

//Mover Obstaculos
for (int i = 0; i < obstaculos.Count; i++)
{
if (obstaculos[i].transform.position.x <= -10)
{
float randomObs = Random.Range(11, 18);
obstaculos[i].transform.position = new Vector3(10, -3, 0);
}
ESCUELA SUPERIOR POLITÉCNICA DE
CHIMBORAZO

obstaculos[i].transform.position = obstaculos[i].transform.position + new Vector3(-1, 0, 0) *


Time.deltaTime * velocidad;
}
}
}
}

 Jugador

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Jugador : MonoBehaviour


{
public float fuerzaSalto;

public GameManager gameManager;

private Rigidbody2D rigidbody2D;

private Animator animator;

// Start is called before the first frame update


void Start()
{
animator = GetComponent<Animator>();
rigidbody2D = GetComponent<Rigidbody2D>();
}

// Update is called once per frame


void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
animator.SetBool("estaSaltando", true);
rigidbody2D.AddForce(new Vector2(0, fuerzaSalto));
}

private void OnCollisionEnter2D(Collision2D collision)


{
if(collision.gameObjet.tag == "Suelo")
{
animator.SetBool("estaSaltando", false);
}
}
if (collision.gameObject.tag == "Obstaculo")
{
gameManager.gameOver = true;
}
}

You might also like