void OnCollisionEnter(Collision coll) { /*Vector3 posDiff = coll.transform.position - transform.position; * transform.position += posDiff.normalized * 20.0f;*/ // Debug.Log (gameObject.name + " BUMPED OFF "+ coll.gameObject.name); Vector3 avgNormal = Vector3.zero; foreach (ContactPoint contact in coll.contacts) { // Debug.DrawRay(contact.point, contact.normal, Color.white); avgNormal += contact.normal; } transform.position += avgNormal.normalized * 15.0f; if (fmodSource) { if (PlayerControl.instance.isDead == false) { fmodSource.StartEvent(); } } else { SoundCenter.instance.PlayClipOn( SoundCenter.instance.bumpSound, transform.position, 1.0f, (GetComponent <PlayerControl>() ? PlayerControl.instance.transform : null)); } Shootable shootableScript = GetComponent <Shootable>(); if (shootableScript && shootableScript.healthLimit > 0) { shootableScript.ExplodeThis(); } }
public void ExplodeThis() { if (alreadyKilledInChain) { return; } alreadyKilledInChain = true; if (isPlayer && Camera.main == null) { return; } // Debug.Log ("KA BOOM"); if (reportDeath) { SpawnTicketBooth.instance.reportDeath(); } if (tag == "Hardpoint") { HardPointCounter hpc = transform.GetComponentInParent <HardPointCounter>(); hpc.RemoveHardpoint(); } foreach (Transform child in transform) { if (child.gameObject.tag == "SurviveAfterParentRemoved") { child.parent = LaserPulseCannon.laserKeeper; child.GetComponent <SelfDestruct>().enabled = true; ParticleSystem psScript = child.GetComponent <ParticleSystem>(); if (psScript) { psScript.enableEmission = false; } } } Collider [] possibleTargets = Physics.OverlapSphere(transform.position, 30.0f); foreach (Collider consider in possibleTargets) { Shootable shootableScript = consider.GetComponent <Shootable>(); if (shootableScript && shootableScript.healthLimit > 0) { shootableScript.ExplodeThis(); } } GameObject.Instantiate( PlayerControl.instance.explodePrefabGeneral, transform.position, Quaternion.identity); if (isPlayer) { // Application.LoadLevel( Application.loadedLevel ); if (GameStateStaticProgress.cheatsOn) { alreadyKilledInChain = false; // so can later die if cheats toggled } else { PlayerControl.instance.PlayerDie(); } } else { // explosions always at max volume, high priority gameplay event, play on camera if (isMegaShipHardPart) { SoundCenter.instance.PlayClipOn( SoundCenter.instance.megashipDamage, Camera.main.transform.position, Random.Range(0.4f, 0.7f), Camera.main.transform); } else { /* SoundCenter.instance.PlayClipOn( * SoundCenter.instance.explodeGeneric, * Camera.main.transform.position, Random.Range(0.25f,0.5f), * Camera.main.transform); */ } Destroy(gameObject); } }