I am making (or at least trying to) make a FPS. I am a begginer and i have know idea how to script. I took a tutorial on how to make a fps and he didn't show me hot to make the grenade do damage. This is my grenade script so far
var creationTime = Time.time;
var explosionPrefab : Transform;
well what kind of turret is it? if it is a turret you go on let me know. if it is a turret controlled by AI, i recommend putting a damage receiver on it.
if you don't have one i will post one below. as for grenade. does it already have damage?
if not go to dastardlybanana.com and download their weapons package. ts VERY helpful. once you've done so find the gunscript from the package or use their premade grenade from their demo scene (f you cant figure it out open the demo scene copy the weapon and camera then paste it into your scene)
here is the damage receiver script (also from dastardly banana
var hitPoints = 100.0;
var detonationDelay = 0.0;
var explosion : Transform;
private var gos : GameObject[];
var deadReplacement : Rigidbody;
function ApplyDamage (damage : float) {
if (hitPoints <= 0.0) {
// We already have less than 0 hitpoints, maybe we got killed already?
}
if (hitPoints <= 0.0)
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 () {
BroadcastMessage ("Detonate");
}
function Detonate () {
// Destroy ourselves
// gos = GameObject.FindGameObjectsWithTag("ScoreCounter");
// for(var go : GameObject in gos){
// go.SendMessage("addScore", pointsValue);
// }
// 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;
}
Destroy(gameObject);
}
// We require the barrel to be a rigidbody, so that it can do nice physics
@script RequireComponent (Rigidbody)