Im still quite new to coding in general, so I apologize for my improper indentation and etc. I learn somewhat from trial and error… but with something a little more complex like this im lost… This script is planned to be used for multiple types of projectiles
so far i have the “on hit specific object hit” working…
but im stuck on if i set it up for timed explosion, how to get it detect nearby colliders
and if “x” collider gets hit apply damage type of deal.
Heres what i got so far, my issues start at line 34 - 49
var bulletLife : int;
var bounces : int;
var explodeOnHit : boolean = true;
var explosionPrefab : Transform;
private var creationTime = Time.time;
var sound : AudioClip;
var damage = 10;
var areaOfEffectDamage : boolean = false;
var explosionRadius : int;
private var startTime;
function Awake () {
}
function Update () {
if (bounces==0){
var explosion = Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy(this.gameObject, 0);
AudioSource.PlayClipAtPoint(sound, transform.position);
Debug.Log("boom");
//AreaDamageEnemies();
}
if (Time.time > (bulletLife+creationTime)) {
Destroy(this.gameObject, 0);
AudioSource.PlayClipAtPoint(sound, transform.position);
var explosion2 = Instantiate(explosionPrefab, transform.position, Quaternion.Euler(Vector3(0, 0, 0)));
Explode();
}
function Explode () {
GameObject.Find("Tank 01");
var colliders : Collider[] = Physics.OverlapSphere (transform.position, radius);
for (var hit : Collider in colliders) {
if (Blocked(hit) != 0)
continue;
//where im gonna apply damage
if (hit.rigidbody)
Debug.Log("area effect boom");
}
}
}
//Basic collision detection checking for two differently named objects
function OnCollisionEnter(theCollision : Collision){
if (explodeOnHit==true && theCollision.gameObject.name == "Tank 01"){
var explosion = Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy(this.gameObject, 0);
AudioSource.PlayClipAtPoint(sound, transform.position);
Debug.Log("tank hit");
}
if(theCollision.gameObject.name == "Cube"){
Debug.Log("Hit the cube");
}else if(theCollision.gameObject.name == "Plane"){
Debug.Log("Hit the wall");
}
else if (theCollision.gameObject.name == "Tank 01") {
theCollision.gameObject.SendMessage("OnDamage", damage);
}
bounces-=1;
}
function PlayAudio () {
}