Skip to content

Instantly share code, notes, and snippets.

@Piwly
Created February 23, 2016 18:54
Show Gist options
  • Save Piwly/09950c11d1c8ee5dfd8f to your computer and use it in GitHub Desktop.
Save Piwly/09950c11d1c8ee5dfd8f to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class BoomGoesBlock : MonoBehaviour {
public static int amount = 0;
private GameObject go;
// Use this for initialization
void Start () {
go = this.gameObject;
}
void OnCollisionEnter2D(Collision2D col)
{
if(amount < 70 && !col.gameObject.GetComponent<BoomGoesBlock>() && !(transform.localScale.x < 0.5f))
SpawnMore ();
}
void SpawnMore()
{
for (int i = 0; i < 4; i++)
{
amount++;
GameObject newGo = Instantiate (go, transform.position, Quaternion.identity) as GameObject;
newGo.transform.localScale = go.transform.localScale/ 2;
newGo.GetComponent<Rigidbody2D> ().AddForce(new Vector2(Random.Range(-100,100),Random.Range(100,300) * 2));
}
Destroy (go);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment