void Shoot() { if (gameObject.tag == "pistolBullet") { pistolGun.Play(); } else if (gameObject.tag == "Laser") { laserGun.Play(); } else if (gameObject.tag == "Blast") { blastGun.Play(); } //shooting logic GameObject bullet = GameObject.Instantiate(bulletPrefab, firePoint.position, firePoint.rotation); Rigidbody2D rb = bullet.GetComponent <Rigidbody2D>(); rb.velocity = transform.right * bulletVelocity * ((characterController.m_FacingRight) ? 1 : -1); bullets b = bullet.GetComponent <bullets>(); b.lifeTime = bulletDistance / bulletVelocity; b.InvokeDestroySelf(); }
public void addBullet(int bullet, int amount) { bullets selection = (bullets)bullet; switch (selection) { case bullets.single: if (totalSingle >= max) { break; } totalSingle += amount; if (totalSingle > max) { totalSingle = max; } break; case bullets.twin: if (totalTwin >= max) { break; } totalTwin += amount; if (totalTwin > max) { totalTwin = max; } break; } }
IEnumerator Shooting() { if (Input.GetMouseButtonDown(0)) { animator.SetTrigger("Shoot"); RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.up); GetComponent <AudioSource>().PlayOneShot(shooting); if (hitInfo) { lr.SetPosition(0, firePoint.position); lr.SetPosition(1, hitInfo.point); enemyA enemyA = hitInfo.transform.GetComponent <enemyA>(); if (enemyA != null) { enemyA.DestroySelf(); } enemyB enemyB = hitInfo.transform.GetComponent <enemyB>(); if (enemyB != null) { enemyB.DestroySelf(); } bullets bullet = hitInfo.transform.GetComponent <bullets>(); if (bullet != null) { bullet.DestroySelf(); } Miniboss miniboss = hitInfo.transform.GetComponent <Miniboss>(); if (miniboss != null) { miniboss.TakeDamage(1); } Boss boss = hitInfo.transform.GetComponent <Boss>(); if (boss != null) { boss.TakeDamage(1); } } else { lr.SetPosition(0, firePoint.position); lr.SetPosition(1, firePoint.position + firePoint.up * 100); } lr.enabled = true; yield return(0.02f); lr.enabled = false; } }
public int getAmount(int bullet) { bullets selection = (bullets)bullet; switch (selection) { case bullets.single: return(totalSingle); case bullets.twin: return(totalTwin); default: return(0); } }
public void fireBullet(int bullet, int number) { bullets selection = (bullets)bullet; Rigidbody shot; Quaternion q; Vector3 forward; switch (selection) { case bullets.single: if (totalSingle <= 0) { audioEmpty.Play(); break; } audioFire.Play(); shot = (Rigidbody)Instantiate(bulletPF.gameObject.GetComponent <Rigidbody>(), transform.position, Quaternion.identity); q = transform.rotation; forward = q * Vector3.forward; shot.AddForce(forward * 20000f, ForceMode.Force); shot.gameObject.tag = "bullet" + number; totalSingle--; break; case bullets.twin: if (totalTwin <= 0) { audioEmpty.Play(); break; } audioFire.Play(); shot = (Rigidbody)Instantiate(doubleBulletPF.gameObject.GetComponent <Rigidbody>(), transform.position, Quaternion.identity); q = transform.rotation; forward = q * Vector3.forward; shot.AddForce(forward * 20000f, ForceMode.Force); shot.gameObject.tag = "bullet" + number; totalTwin--; break; } }
public static bullets instance; // Creating a singleton pattern private void Awake() { instance = this; }