Ok, I guess you guys must hear this lot, but I’m a newbe at this.
Actually, the “shooting” part is doing well. The problem is, once you hold down the mouse botton, it wont stop shooting (and it’s shooting too fast, like a machine gun, ignoring the animation).
Since the gun is suposed to be a shotgun,it should shoot again only when it’s animation (that lasts 14 frames)it’s over.
Here’s the script:
var throwClip: AudioClip;
var myCoconutPrefab:Rigidbody;
var throwForce:int = 20;
static var onPlate:boolean = true;
var canShoot:boolean = true;
var timer:float = 0.0;
function Update ()
{
if (onPlate)
{
if (Input.GetAxis ("Fire1") )
{
timer += Time.deltaTime;
if (timer <= 4.0)
{
canShoot = true;
}
var coco:Rigidbody = Instantiate(myCoconutPrefab, transform.position, transform.rotation);
coco.velocity = transform.TransformDirection(Vector3 (0,0,-throwForce));
Physics.IgnoreCollision(coco.collider, transform.root.collider);
audio.PlayOneShot(throwClip);
if (timer >= 4.0)
{
canShoot = false;
}
}
}
timer =0.0;
I tried to create a time variable that starts when the fire button is pressed. I guessed 4 seconds for the animation’s extendion. If these 4 seconds are not over, the player can’t shoot again. If it’s over, shooting is allowed.
But it’s not working, and the gun’s still shooting like crazy. Can anyone help me?