Created
February 23, 2016 18:54
-
-
Save Piwly/09950c11d1c8ee5dfd8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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