Hello,
I'm working on a flame thrower turret, and I basically have two main scripts attached to the turret, and a damage receiver script attached to the enemy.
One of the scripts on the turret (SmoothLookAt), controls the rotation of the turret when an enemy walks into range.
The other one (FlameController), controls the particle emitter (the flame) and sends the damage to the damage receiver attached to the enemy - which is what I am having a problem with.
I want to follow the FPS tutorial (unity) closely (as my other turrets use the same format), I want to be able to do something like this:
something.SendMessageUpwards("ApplyDamage", flameDamage, SendMessageOptions.DontRequireReceiver);
So I want FlameController to receive if the particles have hit any game objects (enemy), and if so - send the damage to the receiver on the enemy.
I've looked at function OnParticleCollision - but thats a receiver, which means I'll have to place it in my DamageReciever, right?
Well anyway, here are my scripts:
FlameController:
private var flameDamage : float = 0.2;
var flameRange : float;
var flameOn : boolean = false;
var flameParticle : ParticleEmitter;
//ExternalSmooth = gameObject.GetComponentInChildren(SmoothLookAt);
function Update () {
var ExternalSmooth : SmoothLookAt;
ExternalSmooth = gameObject.GetComponentInChildren(SmoothLookAt);
// controls flame particle
if(ExternalSmooth.target){
flameOn = true;
flameParticle.particleEmitter.emit = true;
}
else{
flameOn = false;
flameParticle.particleEmitter.emit = false;
}
// somehow send damge from particle.collider.SendMessageUpwards("ApplyDamage", flameDamage, SendMessageOptions.DontRequireReceiver);
}
DamageReceiver: (from the FSP tutorial - modified slightly)
static var Health;
var hitPoints = 10.0;
var MaxHitPoints = 10.0;
var HealthBarSize : float = 0.2;
var detonationDelay = 0.0;
var explosion : Transform;
var deadReplacement : Rigidbody;
var credits = 100;
private var damageByFlames : float = 0.6;
public var Dead = false;
/*
function OnParticleCollision(){
print("HIT BY FIRE!!");
//currently recieving - i do not want that - i flamecontroller to send damge report
}
*/
function Start(){
Health = Controller.EnemyHealth;
hitPoints = Health;
MaxHitPoints = Health;
}
function Update(){
var script : HealthBar;
script = gameObject.GetComponentInChildren(HealthBar);
script.Health = hitPoints;
script.MaxHealth = MaxHitPoints;
script.MaxBar = HealthBarSize;
}
function ApplyDamage (damage : float) {
// We already have less than 0 hitpoints, maybe we got killed already?
if (hitPoints <= 0.0)
//credits += 100;
return;
hitPoints -= damage;
if (hitPoints <= 0.0) {
// Start emitting particles
var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
if (emitter)
emitter.emit = true;
Invoke("DelayedDetonate", detonationDelay);
}
}
function DelayedDetonate () {
//GetComponent(SmoothLookAt).LookAtDead = false;
BroadcastMessage ("Detonate");
//Dead = true;
}
function Detonate () {
// Destroy ourselves
Credits.Credits += 90;
Controller.EnemyAdding ++;
Destroy(gameObject);
// Create the explosion
if (explosion)
Instantiate (explosion, transform.position, transform.rotation);
// If we have a dead barrel then replace ourselves with it!
if (deadReplacement) {
var dead : Rigidbody = Instantiate(deadReplacement, transform.position, transform.rotation);
// For better effect we assign the same velocity to the exploded barrel
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
// If there is a particle emitter stop emitting and detach so it doesnt get destroyed
// right away
var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
if (emitter) {
emitter.emit = false;
emitter.transform.parent = null;
}
}
// We require the barrel to be a rigidbody, so that it can do nice physics
@script RequireComponent (Rigidbody)
Sorry for the essay, but I'm trying to make my self clear. I would appreciate any help.
Thanks!
Summary:
Any way to do it like this:
OnParticleCollision.SendMessageUpwards("ApplyDamage", flameDamage, SendMessageOptions.DontRequireReceiver);