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

Scrpts

The document contains scripts for a Unity game, including GameManager, BallCollision, BallMovement, and PlayerMovement classes. The GameManager manages the game state, including block counts and scene transitions, while BallCollision handles interactions between the ball and blocks. BallMovement controls the ball's launch mechanics, and PlayerMovement allows player control over movement within defined bounds.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Scrpts

The document contains scripts for a Unity game, including GameManager, BallCollision, BallMovement, and PlayerMovement classes. The GameManager manages the game state, including block counts and scene transitions, while BallCollision handles interactions between the ball and blocks. BallMovement controls the ball's launch mechanics, and PlayerMovement allows player control over movement within defined bounds.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

SCRIPTS

GameManager.cs

using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour


{
private int blocksLeft;

void Start()
{
blocksLeft= GameObject.FindGameObjectsWithTag("Block").Length;
Debug.Log(blocksLeft);
}
public void DecreaseBlocks()
{
blocksLeft--;
Debug.Log(blocksLeft);

if (blocksLeft == 0)
{
LoadNextScene();
}
}

public void LoadNextScene()


{
int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;
SceneManager.LoadScene(nextSceneIndex);
}
public void RestartScene()
{
int activeSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(activeSceneIndex);

public void QuitGame()


{
Application.Quit();
}

}
BallCollision.cs

using UnityEngine;

public class BallCollision : MonoBehaviour


{
GameManager gameManager;

private void Start()


{
gameManager = FindObjectOfType<GameManager>();
}
void OnCollisionEnter2D(Collision2D collision)
{
DestroyIfIsBlock(collision);

private void DestroyIfIsBlock(Collision2D collision)


{
if (collision.gameObject.CompareTag("Block"))
{
Destroy(collision.gameObject);
gameManager.DecreaseBlocks();
}
}

private void OnTriggerEnter2D()


{
gameManager.RestartScene();
}
}
BallMovement.cs

using UnityEngine;

public class BallMovement : MonoBehaviour


{
[SerializeField] Vector2 launchForce;

Rigidbody2D rb;
bool isBallLaunched;
void Start()
{
rb = GetComponent<Rigidbody2D>();

void Update()
{
if (Input.GetButtonDown("Launch") && !isBallLaunched)
{
Launch();
}
}
void Launch()
{
isBallLaunched = true;
rb.AddForce(launchForce);
transform.parent = null;
}
}
PlayerMovement.cs

using UnityEngine;

public class PlayerMovement : MonoBehaviour


{
[SerializeField] float speed;
float bounds = 5.35f;

void Update()
{
Move();
}

void Move()
{
float xInput = Input.GetAxisRaw("Horizontal");
float newPositionX = transform.position.x + speed * xInput * Time.deltaTime;

if (newPositionX < bounds && newPositionX > -bounds)


{
transform.position += new Vector3(speed * xInput * Time.deltaTime, 0f, 0f);
}
}
}
Opciones de Diseño de Niveles

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy