This works pretty well for the most part. It was 2 scripts, but I figured one script might be faster?
This is just a script to control collisions, player/bullet and enemy/bullets, targets.
I’m using tags for effects:
ie- non_destroyable tag should set object on fire(particles) , enemy will make object explode…
So trying to combine, and it works to a degree, but still a couple minor issues.
1- vars: using this script on all objects causes all vars to show on all objects, not just tagged ones. So I have to assign each var Transform to every prefab object (alot of work). I’d prefer to be able to have the prefab particle already listed in the script.
edit:
2- figured this out.
//vars for all collisions
var explosion : Transform;
var fire : Transform;
//will need seperate tags/functions for each enemy type : human (fire), building (fire), enemy (explosion), enemy (explosion)...
function OnTriggerEnter(hit : Collider) //onTriggerEnter | collider
{
//////////////
//non_destroyable collision here : items block bullets, have fire particles, don't die, player will crash into.
//////////
if(hit.gameObject.tag == "non_destroyable")
{
//Destroy(hit.gameObject);
var burn = Instantiate (fire, gameObject.transform.position, Quaternion.identity);
//Destroy(gameObject);
}
else
{
///////////
//player collision here
////////////
if(hit.gameObject.tag == "Player") // registers player crash (ground or building)
{
Destroy(hit.gameObject);
var playerCrash = Instantiate (explosion, gameObject.transform.position, Quaternion.identity);
//Destroy(gameObject); //could destroy building too
//add timer to stall instant menu at crash, maybe anim too
Application.LoadLevel(2); //loads game over menu
UFO_HealthControl.LIVES = 3;
UFO_HealthControl.HITS = 0;
}
//////////////
//enemy collision here
//////////
else
{
if(hit.gameObject.tag == "playerProjectile") // Register player bullets
{
Destroy(hit.gameObject);
var playerKillsEnemy = Instantiate (explosion, gameObject.transform.position, Quaternion.identity);
//Destroy(gameObject);
}
}
}
}