Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions BlockBreaker(LevelManager_script)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;


public class LevelManager : MonoBehaviour
{
public void LoadLevel(string name)
{
Debug.Log("Level load requested for "+name);
block.breakableCount=0;
Application.LoadLevel(name);
}


public void QuitRequest()
{
Debug.Log("I wanna quit!");
Application.Quit();
}

public void LoadNextLevel()
{
block.breakableCount=0;
Application.LoadLevel(Application.loadedLevel+1);
}

public void BrickDestroyed()
{
if(block.breakableCount <=0)
{
LoadNextLevel();
}
}
}
41 changes: 41 additions & 0 deletions BlockBreaker(ball_script)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ball : MonoBehaviour
{
public paddle paddle;
private bool hasStarted = false;

private Vector3 paddleToBallVector;
// Start is called before the first frame update
void Start()
{
paddle = GameObject.FindObjectOfType<paddle>();
paddleToBallVector = this.transform.position - paddle.transform.position;
}

// Update is called once per frame
void Update()
{
if(!hasStarted)
{
this.transform.position = paddle.transform.position + paddleToBallVector;
if(Input.GetMouseButtonDown(0))
{
print("button pressed");
hasStarted = true;
GetComponent<Rigidbody2D>().velocity = new Vector2(Random.Range(1f,2f),Random.Range(7f,9f));
}
}
}

void OnCollisionEnter2D (Collision2D collsion)
{
Vector2 tweak = new Vector2 (Random.Range(0f,0.2f),Random.Range(0f,0.2f));
if (hasStarted)
{
GetComponent<Rigidbody2D>().velocity += tweak;
}
}
}
67 changes: 67 additions & 0 deletions BlockBreaker(block_script)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class block : MonoBehaviour
{
public AudioClip crack;
public Sprite[] hitSprites;
public static int breakableCount = 0;
public GameObject smoke;
private int timesHit;
private LevelManager levelManager;
private bool isBreakable;
// Start is called before the first frame update
void Start()
{
isBreakable = (this.tag=="Breakable");
if(isBreakable)
{
breakableCount++;
print("breakableCount "+breakableCount);
}
timesHit=0;
levelManager = GameObject.FindObjectOfType<LevelManager>();
}

// Update is called once per frame
void Update()
{
}
void OnCollisionEnter2D (Collision2D Col)
{

if (isBreakable)
HandleHits();
}

void HandleHits()
{
timesHit++;
int maxHits = hitSprites.Length+1;

if(timesHit>=maxHits)
{
breakableCount--;
print("breakableCount "+breakableCount);
levelManager.BrickDestroyed();
Destroy(gameObject);
AudioSource.PlayClipAtPoint(crack,transform.position);

}
else {
loadSprites();
}
}
void loadSprites()
{
int spriteIndex = timesHit-1;
if (hitSprites[spriteIndex])
{
this.GetComponent<SpriteRenderer>().sprite =hitSprites[spriteIndex];
}
}



}
18 changes: 18 additions & 0 deletions BlockBreaker(losecollider_script)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class losecollider : MonoBehaviour
{
public LevelManager LevelManager;
void OnTriggerEnter2D (Collider2D trigger)
{
print("Trigger");
}

void OnCollisionEnter2D (Collision2D collision)
{
print("collision");
LevelManager.LoadLevel("lose");
}
}
20 changes: 20 additions & 0 deletions BlockBreaker(paddle_script)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class paddle : MonoBehaviour
{
public bool autoPlay = false;
void Update()
{
MoveWithMouse();
}

void MoveWithMouse()
{
Vector3 paddlePos = new Vector3(0.5f,this.transform.position.y,0f);
float mousePosInBlocks = Input.mousePosition.x / Screen.width * 16;
paddlePos.x = Mathf.Clamp(mousePosInBlocks,1.09f,15.09f);
this.transform.position = paddlePos;
}
}
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# UnityPublic
C#Scripts
C#Scripts used to make a copy of a 2D game "ARKANOID"




{
ball_script = script used to move ball

block_script = script for blocks

levelmanager_script = used for changing scenes

losecollider_script = used for making you lose a game if ball doesnt hits paddle

paddle_script = used for moving paddle
}