//Handles the spawning of the bullet that will damage the player that it hits public void attack() { //Spawn bullet Vector3 position = new Vector3(gunTransform.position.x + .25f, gunTransform.position.y + .025f, gunTransform.position.z); if (player != null) { if (!player.facingRight) { position = new Vector3(gunTransform.position.x - .25f, gunTransform.position.y + .025f, gunTransform.position.z); } } else { if (!player1.facingRight) { position = new Vector3(gunTransform.position.x - .25f, gunTransform.position.y + .025f, gunTransform.position.z); } } GameObject b = (GameObject)Instantiate(bullet, position, gunTransform.rotation); JustinBullet bul = b.GetComponent <JustinBullet>(); if (player != null) { bul.facingRight = player.facingRight; } else { bul.facingRight = player1.facingRight; } bul.damage = damage; b.transform.parent = parent.transform; }
//Handles the attack part of the gun. Spawns a bullet and sets the appropriate properties. public void attack() { if (canAttack) { if (audio != null) { audio.Play(); } //Spawn bullet Vector3 position = new Vector3(gunTransform.position.x + .05f, gunTransform.position.y + .0125f, gunTransform.position.z); if (!player.facingRight) { position = new Vector3(gunTransform.position.x - .05f, gunTransform.position.y + .0125f, gunTransform.position.z); } GameObject b = (GameObject)Instantiate(bullet, position, gunTransform.rotation); JustinBullet bul = b.GetComponent <JustinBullet>(); bul.damage = damage; bul.facingRight = player.facingRight; bul.enemyTag = enemyTag; b.transform.parent = parent.transform; canAttack = false; } }