Advertisement
Placido_GDD

TestScript

Jun 29th, 2021 (edited)
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class TestScript : MonoBehaviour
  7. {
  8.     public bool inCombat;
  9.     protected bool is_Shooting;
  10.     public int max_bcount;
  11.     public float reloadDur;
  12.     public float shottimeLag;
  13.     protected int b_count;
  14.     void Start()
  15.     {
  16.         InvokeRepeating("AI_Routine",0.0f,1.0f);
  17.     }
  18.    
  19.     bool isShooting()
  20.     {
  21.         if(b_count < max_bcount)
  22.         {
  23.             is_Shooting = true;
  24.             return true;
  25.         }
  26.         else
  27.         {
  28.             is_Shooting = false;
  29.             return false;
  30.         }
  31.     }
  32.    
  33.     void AI_Routine()
  34.     {
  35.         if(inCombat == true)
  36.         {
  37.             ShootGun();
  38.         }
  39.     }
  40.    
  41.     void ShootGun()
  42.     {
  43.         InstantiateBullet();
  44.         Reloading();
  45.     }
  46.  
  47.    
  48.     void InstantiateBullet()
  49.     {
  50.         while(b_count < max_bcount)
  51.         {
  52.             StartCoroutine(InstantiateBulletCoroutine());
  53.             //Debug.Log("Spawned a bullet");
  54.             b_count++;
  55.         }
  56.     }
  57.    
  58.     void Reloading()
  59.     {
  60.         if((inCombat == true)&&(is_Shooting == false))
  61.         {
  62.             StartCoroutine(ReloadingCoroutine());
  63.         }
  64.        
  65.     }
  66.    
  67.     IEnumerator InstantiateBulletCoroutine()
  68.     {
  69.         yield return new WaitForSeconds(shottimeLag);
  70.         Debug.Log("Spawned a bullet");
  71.     }
  72.     IEnumerator ReloadingCoroutine()
  73.     {
  74.         inCombat = false;
  75.         yield return new WaitWhile(isShooting);
  76.         Debug.Log("Reloading");
  77.         yield return new WaitForSeconds(reloadDur);
  78.         b_count = 0;
  79.         Debug.Log("Done Reloading");
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement