Created
June 4, 2018 07:50
-
-
Save walkies/c6bcd8b0d0c3e56bb51c3f0ac7c715d1 to your computer and use it in GitHub Desktop.
Blocks, count out
This file contains 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
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