OnExplosionEffect

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: Category: MonoBehaviour Category: CSharp Category: ReallySimpleScripts Author: Opless == Description == Simple Explosion Effect. == CSharp - OnExplosionEffect.cs == <cshar...)
 
Line 1: Line 1:
 
[[Category: MonoBehaviour]]
 
[[Category: MonoBehaviour]]
[[Category: CSharp]]
+
[[Category: C Sharp]]
 
[[Category: ReallySimpleScripts]]
 
[[Category: ReallySimpleScripts]]
  

Revision as of 13:53, 8 November 2007


Author: Opless

Description

Simple Explosion Effect.

CSharp - OnExplosionEffect.cs

<csharp> using UnityEngine; using System.Collections;

public class OnExplosionEffect : MonoBehaviour {

public float radius = 5; public float power = 5; public float upwardForce = 0;

private float radiusUsed = 0.5F;

// Update is called once per frame void FixedUpdate () { // Applies an explosion force to all nearby rigidbodies Vector3 explosionPos = transform.position; Collider[] colliders = Physics.OverlapSphere (explosionPos, radius);

foreach (Collider hit in colliders) { if(hit == null) continue; if (hit.rigidbody) { hit.rigidbody.AddExplosionForce(power, explosionPos, radiusUsed, upwardForce); } } radiusUsed = ((radius-radiusUsed)/2)*Time.deltaTime; }

// Auto destroy public float timeOut = 1.0F;

void Awake () { Invoke ("DestroyNow", timeOut); }

void DestroyNow () {

DestroyObject (gameObject); }


}

</csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox