I'm trying to add a magazine to my gun so people will have to reload, but I don't know how. If someone could help me get a script that displays how many shots are left in the magazine and add a reloading aspect it would be greatly appreciated.
This is my current code:
var DamageAmount : int = 25;
var TargetDistance : float;
var AllowedRange : float = 35;
function Update () {
if(Input.GetKeyDown("mouse 0")) {
var Shot : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Shot)) {
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange) {
Shot.transform.SendMessage("DeductPoints", DamageAmount);
}
}
}
}
and then my sound and animation code is
function Update () {
if(Input.GetKeyDown("mouse 0")) {
var GunSound : AudioSource = GetComponent.();
GunSound.Play();
GetComponent.().Play("shoot");
}
}
sorry that the code wouldn't go in the box
↧