Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerShooting : MonoBehaviour {
  5.  
  6. Animator anim;
  7. public Transform shootingPoint;
  8. public GameObject bullet;
  9. public int ammo = 5;
  10. ParticleSystem muzzle;
  11. PlayerHoldShipPart holding;
  12. bool shooting, rotating;
  13. Transform player;
  14. // Use this for initialization
  15. Transform arm;
  16. float timer = 0;
  17. public float animTime;
  18.  
  19. void Start() {
  20. animTime = 0.8f;
  21. holding = FindObjectOfType<PlayerHoldShipPart>();
  22. player = FindObjectOfType<PlayerHealth>().transform;
  23. anim = FindObjectOfType<PlayerHealth>().GetComponent<Animator>();
  24. muzzle = shootingPoint.GetChild(0).GetComponent<ParticleSystem>();
  25. arm = GameObject.Find("Forearm_L").transform;
  26. }
  27.  
  28. void Update() {
  29. //StartCoroutine(Shoot());
  30. if (Input.GetKeyDown(KeyCode.Space) && !shooting/*&&ammo >0*/
  31. && !holding.holdingShipPart && FindObjectOfType<PlayerGun>().hasGun) {
  32. StartCoroutine(Shoot());
  33. }
  34. }
  35. public bool go = false;
  36. IEnumerator Shoot() {
  37. GetComponent<AudioSource>().Play();
  38. shooting = true;
  39. anim.SetTrigger("Shoot");
  40. yield return new WaitForSeconds(.2f);
  41.  
  42. muzzle.Emit(10);
  43. Instantiate(bullet, shootingPoint.position, shootingPoint.rotation);
  44. ammo -= 1;
  45. FindObjectOfType<InGameUI>().UpdateAmmo(ammo);
  46. yield return new WaitForSeconds(1.5f);
  47. StopCoroutine(Shoot());
  48.  
  49. }
  50. public float x, y;
  51. void LateUpdate() {
  52. if (Input.GetKeyDown(KeyCode.Space)) {
  53. rotating = true;
  54. }
  55. if (rotating) {
  56. timer += Time.deltaTime;
  57. arm.eulerAngles = new Vector3(y, player.eulerAngles.y + 80 + x, Camera.main.transform.eulerAngles.x);
  58. if (timer > animTime) {
  59. rotating = false;
  60. shooting = false;
  61. timer = 0;
  62. }
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement