IEnumerator Crush(ISplitable splitable, int numIterations) { yield return(new WaitForSeconds(0.005f)); //impactPoint = transform.position + 0.5f * transform.forward; for (int i = 0; i < numIterations; i++) { GameObject gocrushPlane = new GameObject("crushPlane", typeof(BoxCollider), typeof(Rigidbody) /*, typeof(SplitterSingleCut)*/); gocrushPlane.GetComponent <Collider>().isTrigger = true; Rigidbody bodycrushPlane = gocrushPlane.GetComponent <Rigidbody>(); bodycrushPlane.useGravity = false; bodycrushPlane.isKinematic = true; Transform transformcrushPlane = gocrushPlane.transform; Bounds bounds = ((Splitable)splitable).GetComponent <Renderer>().bounds; //transformcrushPlane.position = ((Splitable)splitable).transform.position + Random.Range(-bounds.extents.x, bounds.extents.x) * Vector3.right + Random.Range(-bounds.extents.y, bounds.extents.y) * Vector3.up + Random.Range(-bounds.extents.z, bounds.extents.z) * Vector3.forward; transformcrushPlane.position = bounds.center + 0.2f * Random.onUnitSphere; transformcrushPlane.up = Quaternion.AngleAxis(Random.Range(0f, 360f), transform.right) * transform.up; transformcrushPlane.up = Quaternion.AngleAxis(Random.Range(0f, 360f), transformcrushPlane.forward) * transformcrushPlane.up; transformcrushPlane.localScale = new Vector3(20f, .01f, 20f); if ((Splitable)splitable != null) { ((Splitable)splitable).onSplitObject.AddListener(SplitResult); } ((Splitable)splitable).SplitForce = 0; splitable.Split(transformcrushPlane); foreach (var item in lastSplitObjects.ToList()) { if (item != null) { if (item.GetComponent <Splitable>() != null) { item.GetComponent <Splitable>().onSplitObject.AddListener(SplitResult); } item.GetComponent <Splitable>().Split(transformcrushPlane); } } yield return(null); DestroyObject(transformcrushPlane.gameObject); } foreach (var rb in lastSplitObjects.Select(x => x.GetComponent <Rigidbody>())) { //Debug.Log("BOOM"); rb.velocity = Vector3.zero; rb.AddForce(1000 * (rb.transform.position - impactPoint), ForceMode.Impulse); } }
protected virtual void SplitObject(ISplitable splitable, GameObject go) { //ThalmicMyo thalmicMyo = col.myo.GetComponent<ThalmicMyo>(); //thalmicMyo.Vibrate(Thalmic.Myo.VibrationType.Long); go.GetComponent<Renderer>().material.color = Color.red; splitted = true; manager.AddScore(); splitable.Split(_transform); }
void OnTriggerEnter(Collider col) { if (recentCut) { return; } if ((lastSplitObjects.Contains(col.gameObject))) { return; } ISplitable splitable = null; MonoBehaviour[] components = col.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour component in components) { splitable = component as ISplitable; if (splitable != null) { break; } } if (splitable != null) { //GetComponent<Collider>().enabled = false; //Invoke("EnableCollider", 0.1f); Debug.Log("Collided"); recentCut = true; cutTimer = 0f; lastSplitObjects.Add(col.gameObject); StartCoroutine(RemoveFromList(col.gameObject)); GameObject goCutPlane = new GameObject("CutPlane", typeof(BoxCollider), typeof(Rigidbody) /*, typeof(SplitterSingleCut)*/); goCutPlane.GetComponent <Collider>().isTrigger = true; Rigidbody bodyCutPlane = goCutPlane.GetComponent <Rigidbody>(); bodyCutPlane.useGravity = false; bodyCutPlane.isKinematic = true; Transform transformCutPlane = goCutPlane.transform; transformCutPlane.position = transform.position; transformCutPlane.up = -transform.forward; // transform.up; transformCutPlane.localScale = new Vector3(20f, .01f, 20f); if ((Splitable)splitable != null) { ((Splitable)splitable).onSplitObject.AddListener(SplitResult); } splitable.Split(transformCutPlane); DestroyObject(transformCutPlane.gameObject); } }
protected override void SplitObject(ISplitable splitable, GameObject go) { splitable.Split(_transform); _hasCut = true; }
protected virtual void SplitObject(ISplitable isplitable, GameObject go) { isplitable.Split(_transform); }
protected override void SplitObject(ISplitable splitable, GameObject go) { Debug.Log("Transform:" + _transform.position); splitable.Split(_transform); _hasCut = true; }
protected virtual void SplitObject(ISplitable splitable, GameObject go) { splitable.Split(_transform); }