Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Soldier : EnemyBase
- {
- public bool soldier_InCombat;
- public GameObject soldier_proj;
- protected GameObject projectile;
- public Transform muzzle;
- public float delayBetweenShots;
- public float proj_force;
- public int b_BurstCount;
- protected int burstCounter;
- protected bool isPatrolling;
- protected bool isReloading;
- protected Transform soldier_Target;
- protected Rigidbody2D proj_RB;
- public override void Init()
- {
- base.Init();
- Health = base.health;
- isReloading = false;
- soldier_Target = base.player_script.transform;
- if(base.waypoints.Length < 2)
- {
- base.anim.SetTrigger("Idle");
- isPatrolling = false;
- soldier_Target = base.player_script.transform;
- }
- else if(base.waypoints.Length >= 2)
- {
- //Debug.Log("Following waypoint paths");
- isPatrolling = true;
- }
- }
- public override void Update()
- {
- SoldierAI_Update();
- }
- void SoldierAI_Update()
- {
- if(isPatrolling == true)
- {
- base.Update();
- }
- if(isPatrolling == false)
- {
- if(base.isDead == false)
- {
- base.DeathCheck();
- base.FaceTarget();
- base.TargetDistanceCheck();
- CombatCheck();
- }
- }
- }
- void CombatCheck()
- {
- if(soldier_Target.position.y >= transform.position.y)
- {
- soldier_InCombat = base.inCombat;
- }
- else if(soldier_Target.position.y < transform.position.y)
- {
- soldier_InCombat = false;
- }
- if(soldier_InCombat == true)
- {
- ShootAtTarget();
- }
- else if(soldier_InCombat == false)
- {
- base.anim.SetBool("InCombat",false);
- base.anim.SetTrigger("Idle");
- }
- }
- void ShootAtTarget()
- {
- base.anim.SetBool("IsShooting",true);
- //check if in the state reloading if not instantiate proj and force
- if(isReloading == false)
- {
- while(burstCounter <= b_BurstCount)
- {
- Debug.Log("Burst Count:" + burstCounter);
- Rigidbody2D proj_RB;
- GameObject projectile;
- projectile = Instantiate(soldier_proj,muzzle.position,muzzle.rotation);
- proj_RB = projectile.GetComponent<Rigidbody2D>();
- if((base.isFlipped == false)&&(base.isFacingLeft == true))
- {
- proj_RB.AddForce(transform.right * -proj_force,ForceMode2D.Impulse);
- }
- else if((base.isFlipped == true)&&(base.isFacingLeft == false))
- {
- proj_RB.AddForce(transform.right * proj_force,ForceMode2D.Impulse);
- }
- burstCounter++;
- }
- base.anim.SetBool("IsShooting",false);
- isReloading = true;
- Debug.Log("Is reloading:" + isReloading);
- StartCoroutine(SoldierFireRate());
- }
- }
- IEnumerator SoldierFireRate()
- {
- yield return new WaitForSeconds(delayBetweenShots);
- isReloading = false;
- base.anim.SetBool("IsShooting",false);
- burstCounter = 0;
- Debug.Log("Is reloading:" + isReloading);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement