1911 script

can someone help me with this script I want to make it so the if I hit the r key it plays my reload animation and refills the gun
var bullet : Rigidbody;
var power : float = 1500;
var damage : float = 100;
var reloadtime : float = 4; // this reload time is too long!
var magcount : int = 10;
var magbulletcount : int = 21;
var bulletcount : int = 0;
var Reload : AnimationClip;
var Idel : AnimationClip;
var AutoFire : AnimationClip;
var ReloadAudio : AudioClip;
var AutoFireAudio : AudioClip;
var CockAudio : AudioClip;

private var reloadTimer: float = 0.0; // internal reload timer

function Start () {
bulletcount = magbulletcount;
}

function Update(){
if (reloadTimer > 0){ // if reloadTimer active…
reloadTimer -= Time.deltaTime; // decrement it
if (reloadTimer <= 0){ // if reloadTime ended…
bulletcount = magbulletcount; // load a full clip…
magcount–; // and decrement clip count
}
}
else // only shoot when reloadTimer not active
if (Input.GetButtonDown(“Fire1”) bulletcount > 0){
animation.Play(“AutoFire_1911”);
audio.PlayOneShot(AutoFireAudio);

var instance: Rigidbody = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
var fwd: Vector3 = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd * power);
bulletcount --;
if (bulletcount <= 0 magcount > 0){

// if run out of ammo but still have clips…
reloadTimer = reloadtime; // activate reloadTimer
// you can play reload sound or animation here
animation.Play(“Reload_1911”);
audio.PlayOneShot(ReloadAudio);
audio.PlayOneShot(CockAudio);
}

}
}

Here is pseudo-code. You should pick up on the general idea.

var magazineCapacity : int = (Some number);
var currentAmmo : int = (Some number);

var reloadAnim : AnimationClip;

if (Input.GetKeyDown("r")){

    currentAmmo = magazineCapacity;

    animation.Play("reloadAnim");
}

Edit:

To add a reload time you should check this out: Unity - Scripting API: WaitForSeconds

No one is going to write your script for you. If you have a specific difficulty, you can post the script using the “CODE” tags and someone can probably give you some advice.

Arcade-style gun reloading scripts are easy. Just add rounds to the gun and subtract from your total. More realistic behaviour with a slide catch, hammer cocking-decocking, chamber full/empty, magazine capacities, etc. is a bit more complicated, but it is nothing that can’t be solved with basic programming skills.