- Home /
Problem with Ammo/Shoot script
Hello!
I have a problem with my ammo and shoot script. If I click the left mouse button it should shoot a projectil but I does not anything. Here is the script:
var projectile : Rigidbody;
var speed = 20;
var MaxAmmo = 6;
var CurrentAmmo = 6;
var shotsFired = 0;
var canFire = true;
var canShootAgain = true;
function Update()
{
}
function Shooting () {
if (canFire == true)
{
if(canShootAgain == true)
{
if (Input.GetButton("Fire 1"))
{
canShootAgain = false;
var instantiatedProjectile : Rigidbody = Instantiate(projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,transform.root.collider );
CurrentAmmo -= 1;
shotsFired +=1;
yield WaitForSeconds (1.5);
canShootAgain = true;
if(CurrentAmmo == 0)
{
canFire = false;
}
}
}
}
}
It is a similar script which is somewhere posted.
Answer by Yokimato · Aug 15, 2013 at 06:26 PM
I don't see where you're calling the function Shooting
. Did you mean to have that in Update?? such that:
function Update()
{
Shooting();
}
Answer by TheRichardGamer · Aug 15, 2013 at 06:52 PM
You'd want to put all of your if statements inside the update function, in this script you aren't calling anything.
Hope this helps! ^_^
Your answer
Follow this Question
Related Questions
How To Disable/Enable Function 2 Answers
Make the animation play at the start of the time waited, not the end of it? 1 Answer
Shooting Specific GameObject via Tag 0 Answers
Shootin Worminator Like Game 3 Answers
Shoot script help 1 Answer