public override void OnInspectorGUI() { base.OnInspectorGUI(); BluePart BP = (BluePart)target; if (GUILayout.Button("Break")) { BP.Break(); } }
void OnTriggerEnter(Collider C) { try { BluePart Part = C.GetComponent <BluePart>(); if (Part != null && Part != BP) { FoundNeighbors.Add(Part); } }catch {} }
void OnCollisionEnter(Collision col) { if (EditorMode) { try { BluePart Part = col.gameObject.GetComponent <BluePart>(); if (Part != null) { Neighbors.Add(Part); } }catch {} } }
public void ThisBroke(BluePart BP, List <int> BrokeDists) { Neighbors.Remove(BP); //The broken object is no longer a neighbor if (Neighbors.Count == 0 && !GroundPart) //if is alone and isn't attached to the ground { Break(); } else { MarkPaths(BrokeDists); //Find paths that are broken now RecalculateIndex(); //Recalculate what path should be used as closest if (OutOfPaths()) //No paths are free thus it's floating/not supported { Break(); //break it if there are no paths left } } }
void SpawnExplosion(Vector3 Start) { LastPos = Start; if (Start != Vector3.zero) { Collider[] hitColliders = Physics.OverlapSphere(Start, Radius); int i = 0; while (i < hitColliders.Length) { try { BluePart Part = hitColliders[i].GetComponent <BluePart>(); if (Part != null) { Part.Break(); } }catch {} try { Rigidbody R = hitColliders[i].GetComponent <Rigidbody>(); if (R != null) { Vector3 Direction = hitColliders[i].transform.position - Start; float percent = (Vector3.Distance(hitColliders[i].transform.position, Start)) / (Radius); if (percent > 1) { percent = 1; } percent = Magnitude * (1 - percent); R.AddForce(Direction.normalized * percent); } }catch {} i++; } } }