Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void InitialiseShoot()
- {
- if (currentAmmo > 0)
- {
- muzzleFlash.Play();
- shootAnimator.SetBool("Shoot", true);
- currentAmmo--;
- if (gameObject.name == "Shotgun")
- {
- for (int i = 0; i < 10; i++)
- {
- var forward = cam.transform.forward;
- forward.x += Random.Range(-.05f, .05f);
- forward.y += Random.Range(-.05f, .05f);
- forward.z += Random.Range(-.05f, .05f);
- Shoot(forward);
- }
- }
- else
- {
- var forward = cam.transform.forward;
- Shoot(forward);
- }
- }
- }
- void Shoot(Vector3 forward)
- {
- RaycastHit hit;
- if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, weapon.range))
- {
- if (hit.collider.tag == "Enemy")
- {
- Enemy enemy = hit.transform.GetComponent<Enemy>();
- enemy.TakeDamage(weapon.damage);
- }
- else
- {
- if (hit.collider.tag == "Destructible")
- {
- Destructible destructible = hit.collider.gameObject.GetComponent<Destructible>();
- destructible.TakeDamage(weapon.damage);
- hit.rigidbody.AddForce(-hit.normal * weapon.impactForce);
- }
- }
- GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
- Destroy(impactGO, 2f);
- }
- }
Add Comment
Please, Sign In to add comment