Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class SoldierRifle : MonoBehaviour
- {
- public bool gunCombat;
- protected bool is_Shooting;
- public int max_bcount;
- public float reloadDur;
- public float shottimeLag;
- protected int b_count;
- void Start()
- {
- b_count = 0;
- InvokeRepeating("AI_Routine",0.0f,1.0f);
- }
- bool isShooting()
- {
- if(b_count < max_bcount)
- {
- is_Shooting = true;
- return true;
- }
- else
- {
- is_Shooting = false;
- return false;
- }
- }
- public void AI_Routine()
- {
- if(gunCombat == true)
- {
- ShootGun();
- }
- }
- public void ShootGun()
- {
- StartCoroutine(InstantiateBulletCoroutine());
- Reloading();
- }
- void Reloading()
- {
- if((gunCombat == true)&&(is_Shooting == false))
- {
- StartCoroutine(ReloadingCoroutine());
- }
- }
- IEnumerator InstantiateBulletCoroutine()
- {
- while(b_count < max_bcount)
- {
- yield return new WaitForSecondsRealtime(shottimeLag);
- //do instantiate bullet things//
- // //
- Debug.Log("Spawn Bullet");
- b_count++;
- }
- }
- IEnumerator ReloadingCoroutine()
- {
- gunCombat = false;
- yield return new WaitWhile(isShooting);
- Debug.Log("Reloading");
- yield return new WaitForSecondsRealtime(reloadDur);
- b_count = 0;
- Debug.Log("Done Reloading");
- StopAllCoroutines();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement