imagination XD

realizing dream

[EFTL] Some Legacy Script

Leave a comment

To create a script like a grenade will explode / damaging other object on certain radius.

// Explosive Object. For example OnColliderDamage.js
var explosionPrefab : Transform;
var damage : float;
var explosionPower = 5.0;
var radius = 6.0;

function OnCollisionEnter(col : Collision){
  var colliders = Physics.OverlapSphere(transform.position,radius);
  for(var hit in colliders){
      var body = hit.gameObject.rigidbody;
      if(body) hit.rigidbody.AddExplosionForce
// to know how large the radius is.
function OnDrawGizmosSelected(){
    Gizmos.color = Color.cyan;

and this is the script that attached to object to explode. 
For instance (DestructableObj.js)
var explosion : Transform;
var hitPoints = 100.0;

function ApplyDamage(damage : float){
    if(hitPoints <= 0.0) return;
    hitPoints -= damage;
    if(hitPoints <= 0.0) Explode();

function Explode(){

It’s the simple script that i use for explosion for Escape From the Laboratories and Catapult. You also can make the explosive type at OnCollisionDamage.js script by using enum. For instance

enum Explosive {TNT,Nitro}
var explosiveType : Explosive;
var timeOut = 3.0;

function OnCollisionEnter(col : Collision){
if(explosiveType == Explosive.TNT) PlayBeeps();
else if(explosiveType == Explosive.Nitro) Explode();

function PlayBeeps(){
    audio.clip = beep;
    if(audio && !audio.isPlaying) audio.Play();
    yield new WaitForSeconds (timeOut);

function HandlerFunc(){audio.Stop(); Explode();}


Started making games since 13 year old. 3D CGI Weeaboo | VFX Otaku | Anime Researcher | Indie Game Dev | VR Chuunibyou


Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s