void Awake() { healthScript = GetComponent<HealthFighter> (); engineScript = GetComponent<EnginesFighter> (); shootScript = GetComponentInChildren<WeaponsPrimaryFighter> (); missilesScript = GetComponentInChildren<WeaponsSecondaryFighter> (); myRigidbody = GetComponent<Rigidbody2D> (); if (whichSide == WhichSide.Ally) { myCommander = GameObject.FindGameObjectWithTag("AIManager").transform.FindChild("PMC Commander").GetComponent<AICommander> (); enemyCommander = GameObject.FindGameObjectWithTag("AIManager").transform.FindChild("Enemy Commander").GetComponent<AICommander> (); } else if (whichSide == WhichSide.Enemy) { myCommander = GameObject.FindGameObjectWithTag("AIManager").transform.FindChild("Enemy Commander").GetComponent<AICommander> (); enemyCommander = GameObject.FindGameObjectWithTag("AIManager").transform.FindChild("PMC Commander").GetComponent<AICommander> (); } myCommander.myFighters.Add (this.gameObject); normalStates = new StateMachine[]{StateMachine.Patroling}; combatStates = new StateMachine[]{StateMachine.Dogfight}; formUpStates = new StateMachine[]{StateMachine.FormUp}; coverMeStates = new StateMachine[]{StateMachine.Covering}; retreatStates = new StateMachine[] {StateMachine.Evade, StateMachine.Retreat}; deathStates = new StateMachine[] {StateMachine.NA}; }
void Awake() { if(instance == null) { instance = this; } else { Debug.LogError("There were 2 PlayerAILogic scripts"); Destroy(gameObject); return; } healthScript = GetComponent<HealthFighter> (); engineScript = GetComponent<PlayerFighterMovement> (); shootScript = GetComponentInChildren<WeaponsPrimaryFighter> (); missilesScript = GetComponentInChildren<WeaponsSecondaryFighter> (); dodgeScript = GetComponentInChildren<Dodge>(); }
protected void DogfightingFunction(EnginesFighter engineScript, GameObject target, WeaponsPrimaryFighter shootScript, float constantForwardThrustProportion) { //NB: It's important that we move before look, because the firing solution (in look) requires knowing the new movement position of the target engineScript.LookAtTarget (target); if(Vector2.Angle(transform.up, target.transform.position - transform.position) < 60) { engineScript.MoveToTarget (target, constantForwardThrustProportion); } if(Time.time > shootScript.nextFire && (ReadyAimFire(target, transform, shootScript.weaponsRange) == true || TakePotshot(transform, shootScript.weaponsRange) == true)) { if(shootScript.enabled) { shootScript.FirePrimary(false); } } }