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 TestScript : MonoBehaviour
- {
- public bool inCombat;
- protected bool is_Shooting;
- public int max_bcount;
- public float reloadDur;
- public float shottimeLag;
- protected int b_count;
- void Start()
- {
- 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;
- }
- }
- void AI_Routine()
- {
- if(inCombat == true)
- {
- ShootGun();
- }
- }
- void ShootGun()
- {
- InstantiateBullet();
- Reloading();
- }
- void InstantiateBullet()
- {
- while(b_count < max_bcount)
- {
- StartCoroutine(InstantiateBulletCoroutine());
- //Debug.Log("Spawned a bullet");
- b_count++;
- }
- }
- void Reloading()
- {
- if((inCombat == true)&&(is_Shooting == false))
- {
- StartCoroutine(ReloadingCoroutine());
- }
- }
- IEnumerator InstantiateBulletCoroutine()
- {
- yield return new WaitForSeconds(shottimeLag);
- Debug.Log("Spawned a bullet");
- }
- IEnumerator ReloadingCoroutine()
- {
- inCombat = false;
- yield return new WaitWhile(isShooting);
- Debug.Log("Reloading");
- yield return new WaitForSeconds(reloadDur);
- b_count = 0;
- Debug.Log("Done Reloading");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement