Created
June 5, 2018 05:09
-
-
Save walkies/677887e45d6e30fa2cc3f0cefeeaa3a4 to your computer and use it in GitHub Desktop.
blocks revised
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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Blocks : MonoBehaviour { | |
public float thrust; | |
public Rigidbody rbB; | |
public GameObject myPrefab; | |
public Material Mat; | |
public Material[] randomMaterials; | |
public Transform dropPoint; | |
public Countdown count; | |
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(); | |
} | |
else if (B.gameObject.tag == "Block") | |
{ | |
Vector3 dir = B.contacts[0].point - transform.position; | |
dir = -dir.normalized; | |
rbB.AddForce(dir * thrust); | |
} | |
else if (B.gameObject.tag == "Floor") | |
{ | |
count.currentTime++; | |
count.currentScore++; | |
} | |
} | |
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