Skip to content

Instantly share code, notes, and snippets.

@walkies
Created June 4, 2018 07:50
Show Gist options
  • Save walkies/c6bcd8b0d0c3e56bb51c3f0ac7c715d1 to your computer and use it in GitHub Desktop.
Save walkies/c6bcd8b0d0c3e56bb51c3f0ac7c715d1 to your computer and use it in GitHub Desktop.
Blocks, count out
public class Blocks : MonoBehaviour {
public float thrust;
public Rigidbody rbB;
public GameObject myPrefab;
public Material Mat;
public Material[] randomMaterials;
public Transform dropPoint;
float x;
float z;
void Start()
{
rbB = GetComponent<Rigidbody>();
rbB.AddForce(transform.forward * thrust);
Mat = randomMaterials[Random.Range(0, randomMaterials.Length)];
GetComponent<Renderer>().sharedMaterial = Mat;
}
void Update () {
}
void OnCollisionEnter(Collision B)
{
if (B.gameObject.tag == "Ball")
{
Vector3 dir = B.contacts[0].point - transform.position;
dir = -dir.normalized;
rbB.AddForce(dir * thrust * 25);
instantiate();
}
if (B.gameObject.tag == "Block")
{
Vector3 dir = B.contacts[0].point - transform.position;
dir = -dir.normalized;
rbB.AddForce(dir * thrust);
}
}
void OnCollisionStay(Collision BB)
{
if (BB.gameObject.tag == "Block")
{
Vector3 dir = BB.contacts[0].point - transform.position;
dir = -dir.normalized;
rbB.AddForce(dir * thrust);
}
}
void instantiate()
{
x = Random.Range(-2, 2);
z = Random.Range(-2, 2);
Instantiate(myPrefab, new Vector3(x, 3f, z), Quaternion.identity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment