Guest User

Untitled

a guest
Jun 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. void InitialiseShoot()
  2. {
  3. if (currentAmmo > 0)
  4. {
  5. muzzleFlash.Play();
  6.  
  7. shootAnimator.SetBool("Shoot", true);
  8.  
  9. currentAmmo--;
  10.  
  11. if (gameObject.name == "Shotgun")
  12. {
  13. for (int i = 0; i < 10; i++)
  14. {
  15. var forward = cam.transform.forward;
  16. forward.x += Random.Range(-.05f, .05f);
  17. forward.y += Random.Range(-.05f, .05f);
  18. forward.z += Random.Range(-.05f, .05f);
  19.  
  20. Shoot(forward);
  21. }
  22. }
  23. else
  24. {
  25. var forward = cam.transform.forward;
  26. Shoot(forward);
  27. }
  28. }
  29. }
  30.  
  31. void Shoot(Vector3 forward)
  32. {
  33. RaycastHit hit;
  34. if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, weapon.range))
  35. {
  36. if (hit.collider.tag == "Enemy")
  37. {
  38. Enemy enemy = hit.transform.GetComponent<Enemy>();
  39. enemy.TakeDamage(weapon.damage);
  40. }
  41. else
  42. {
  43. if (hit.collider.tag == "Destructible")
  44. {
  45. Destructible destructible = hit.collider.gameObject.GetComponent<Destructible>();
  46. destructible.TakeDamage(weapon.damage);
  47. hit.rigidbody.AddForce(-hit.normal * weapon.impactForce);
  48. }
  49. }
  50. GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
  51. Destroy(impactGO, 2f);
  52. }
  53. }
Add Comment
Please, Sign In to add comment