Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerShooting : MonoBehaviour {
- Animator anim;
- public Transform shootingPoint;
- public GameObject bullet;
- public int ammo = 5;
- ParticleSystem muzzle;
- PlayerHoldShipPart holding;
- bool shooting, rotating;
- Transform player;
- // Use this for initialization
- Transform arm;
- float timer = 0;
- public float animTime;
- void Start() {
- animTime = 0.8f;
- holding = FindObjectOfType<PlayerHoldShipPart>();
- player = FindObjectOfType<PlayerHealth>().transform;
- anim = FindObjectOfType<PlayerHealth>().GetComponent<Animator>();
- muzzle = shootingPoint.GetChild(0).GetComponent<ParticleSystem>();
- arm = GameObject.Find("Forearm_L").transform;
- }
- void Update() {
- //StartCoroutine(Shoot());
- if (Input.GetKeyDown(KeyCode.Space) && !shooting/*&&ammo >0*/
- && !holding.holdingShipPart && FindObjectOfType<PlayerGun>().hasGun) {
- StartCoroutine(Shoot());
- }
- }
- public bool go = false;
- IEnumerator Shoot() {
- GetComponent<AudioSource>().Play();
- shooting = true;
- anim.SetTrigger("Shoot");
- yield return new WaitForSeconds(.2f);
- muzzle.Emit(10);
- Instantiate(bullet, shootingPoint.position, shootingPoint.rotation);
- ammo -= 1;
- FindObjectOfType<InGameUI>().UpdateAmmo(ammo);
- yield return new WaitForSeconds(1.5f);
- StopCoroutine(Shoot());
- }
- public float x, y;
- void LateUpdate() {
- if (Input.GetKeyDown(KeyCode.Space)) {
- rotating = true;
- }
- if (rotating) {
- timer += Time.deltaTime;
- arm.eulerAngles = new Vector3(y, player.eulerAngles.y + 80 + x, Camera.main.transform.eulerAngles.x);
- if (timer > animTime) {
- rotating = false;
- shooting = false;
- timer = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement