public void Smash() { broken = true; //the Corks collider needs to be turned on; if (Cork != null) { Cork.transform.parent = null; Cork.GetComponent <Collider>().enabled = true; Cork.GetComponent <Rigidbody>().isKinematic = false; Destroy(Cork.gameObject, DespawnTime); } //the Liquid gets removed after n seconds if (Liquid != null) { float t = 0.0f; //if (Effect != null) // t = (Effect.main.startLifetime.constantMin + Effect.main.startLifetime.constantMax)/2; Destroy(Liquid.gameObject, t); } //particle effect if (Effect != null) { Effect.Play(); Destroy(Effect.gameObject, Effect.main.startLifetime.constantMax); } //now the label; if (Label != null) { //Label.transform.parent = null; //Label.GetComponent<Collider>().enabled = true; //Label.GetComponent<Rigidbody>().isKinematic = false; Destroy(Label.gameObject); } //turn Glass off and the shattered on. if (Glass != null) { Destroy(Glass.gameObject); } if (Glass_Shattered != null) { Glass_Shattered.SetActive(true); Glass_Shattered.transform.parent = null; Destroy(Glass_Shattered, DespawnTime); } //instantiate the splat. RaycastHit info = new RaycastHit(); if (Splat != null) { if (Physics.Raycast(transform.position, Vector3.down, out info, maxSplatDistance, SplatMask)) { GameObject newSplat = Instantiate(Splat); newSplat.transform.position = info.point; } } Destroy(transform.gameObject, DespawnTime); }
public void Smash() { broken = true; audio.Play(); //the Corks collider needs to be turned on; if (Cork != null) { Cork.transform.parent = null; Cork.GetComponent <Collider>().enabled = true; Cork.GetComponent <Rigidbody>().isKinematic = false; Destroy(Cork.gameObject, DespawnTime); } //the Liquid gets removed after n seconds if (Liquid != null) { float t = 0.0f; //if (Effect != null) // t = (Effect.main.startLifetime.constantMin + Effect.main.startLifetime.constantMax)/2; Destroy(Liquid.gameObject, t); } //particle effect if (Effect != null) { Effect.Play(); Destroy(Effect.gameObject, Effect.main.startLifetime.constantMax); } //now the label; //turn Glass off and the shattered on. if (Glass != null) { Destroy(Glass.gameObject); } if (Glass_Shattered != null) { Glass_Shattered.SetActive(true); Glass_Shattered.transform.parent = null; Destroy(Glass_Shattered, DespawnTime); } //instantiate the splat. RaycastHit info = new RaycastHit(); if (Splat != null) { if (Physics.Raycast(transform.position, Vector3.down, out info, maxSplatDistance, SplatMask)) { //GameObject newSplat = Instantiate(Splat); //newSplat.transform.position = info.point; } } Destroy(transform.gameObject, DespawnTime); //Explosion power Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); foreach (Collider hit in colliders) { Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(power, explosionPos, radius, 3.0F); } } }