Hi,
I’m trying to make a game were the player needs to find a bullet and a gun to shoot an enemy.
So I have tried to write a reload script which is attached to the Player and goes like this:
var canReload = false;
var carryingGun = false;
var carryingBullet = false;
var collisionGun : Collider;
var collisionBullet : Collider;
var reloadTime = 3;
var bullets = 1;
var pickupGunSound : AudioClip;
var pickupBulletSound : AudioClip;
function OnCollisionEnter(collision : Collision)
{
if (collisionGun.gameObject.tag == "gun"); // collide with the Gun...
carryingGun = true; // ...to pick it up
audio.PlayOneShot(pickupGunSound);
Debug.Log( "YOU HAVE THE GUN" ); // "You have the gun. Find the bullet"
if (collisionBullet.gameObject.tag == "bullet") // collide with the Bullet...
carryingBullet = true; // ...to pick it up
audio.PlayOneShot(pickupBulletSound);
Debug.Log( "YOU HAVE THE BULLET" ); // "You have the bullet. Find the gun"
}
function Reload ()
{
if (carryingGun == true)
canReload = true;
Debug.Log( "YOU CAN RELOAD" );
if (carryingBullet == true)
canReload = true; // ...you can reload
Debug.Log( "YOU CAN RELOAD" ); // "You have the bullet and the gun. Reload now (press R)!"
if(canReload == true)
if (Input.GetKeyDown("R"))
{
yield WaitForSeconds (reloadTime); // wait 3 seconds
bullets = 1; // there is one bullet in the Gun
Debug.Log( "THE GUN IS LOADED" ); // "The Gun is Loaded. Shoot the enemy !"
}
}
So the console sends no errors back and I get the debug.log for carryingGun=true and carryingBullet=true, but I can"t get the canReload=true and reload state.
Please, can you correct my code or help me see what I’m missing here.
Thanks.