public var lifeTime : int = 1;
function OnTriggerEnter () {
Destroy(gameObject, lifeTime);
}
Hi guys, I created a 1st person controller with a gun, and its shooting and working fine, and killing my enemies but I want to end with an explosion after they are killed. So, I dont know exactly how to put this down in the script. Above you see my first version and after this text, my second version, it doesnt give too much error but it just isnt working... please help me.
public var lifeTime : int = 1;
var explosion : Transform;
function OnTriggerEnter () {
Destroy(gameObject, lifeTime);
}
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject == "Bulletspawn")
{
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
And this is the rest of the script:
- Shotgun Script (for the gun)
- public var bulletPrefab : Transform;
- public var bulletSpeed : float = 6000;
- var ammo : int = 60;
- var gunShot : AudioClip;
- var reload : AudioClip;
- var emptyClip : boolean = false;
-
- if(Input.GetButtonDown(“Fire1”)) {
- if(ammo > 0) {
- Shoot();
- }
- else
- {
- return;
- }
- }
- if (Input.GetKeyDown (KeyCode.R)) {
- if (emptyClip) {
- Reload();
- }
- }
- if (ammo > 0) {
- emptyClip = true;
- }
- else
- {
- emptyClip = false;
- }
- }
-
- var bullet = Instantiate(bulletPrefab, transform.Find(“Bulletspawn”).position, transform.Find(“Bulletspawn”).rotation);
- bullet.tag = “BulletspawnProjectile”;
- bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
- audio.PlayOneShot (gunShot) ;
- ammo–;
- }
-
- audio.PlayOneShot(reload);
- ammo = 60;
- }
-
- GUI.Label (Rect ( 0,0, 75, 25), "Ammo " + ammo) ;
- }
Please… someone?
Hallo Eric,
I am very new to Unity, and I am not exactly sure where it is the best to post my stuff, that is why I dublicated it, if I understand well, in two
different categories (or am I wrong??), one with the question section (I guess thats for amatueurs like me) and the other one in the scripting section. About Code tags, I cannot really find the right buttons, I am here now for a week or two, so sorry for that, but I will try to improve.
Greetings, Maurice
As I said, posting duplicates is against the rules. Pick one category only please. You can use the advanced editor (click on “go advanced”) for a code tag button, or just type them manually. http://forum.unity3d.com/threads/143875-Using-code-tags-properly When you’re new to a forum, it’s good to look around and read the stickies/readme topics first.
–Eric
Ok, I will try to delete asap!