IEnumerator Shoot() { currWep = wep.GetCurrWeapon(); if (nav) { if (nav.isActiveAndEnabled) { nav.Stop(); } } if (aiPerception.Target) { Vector3 opponentPos = aiPerception.Target.position - new Vector3(0, aiPerception.Target.position.y, 0); transform.LookAt(opponentPos); currWep.transform.LookAt((aiPerception.Target.position) + aiPerception.Target.up * 0.5f); RaycastHit hit; if (Physics.Raycast(currWep.transform.position, currWep.transform.forward, out hit, currWep.weaponRange)) { if (hit.transform.tag == aiPerception.Target.tag) { if (aiPerception.Target.GetComponent <Movement_Handler>().isAlive) { wep.useWeapon(true); } } } } yield return(new WaitForSeconds(1)); wep.useWeapon(false); if (movHdlr.isAlive) { if (nav) { if (nav.isActiveAndEnabled) { nav.Resume(); } } } }
void Update() { if (Time.timeScale != 0) { if (!mov.isAlive) { this.enabled = false; } if (Input.GetButton("Fire")) { wep.useWeapon(true); } if (Input.GetButtonUp("Fire")) { wep.useWeapon(false); } if (Input.GetButtonDown("Reload")) { wep.Reload(); } if (Input.GetButtonDown("Next Weapon")) { wep.changeWeapon(1); } else if (Input.GetButtonDown("Previous Weapon")) { wep.changeWeapon(-1); } if (Input.GetKey("escape")) { if (cursorHidden) { Cursor.visible = true; } else { Cursor.visible = false; } } if (Input.GetButtonDown("Aim")) { wep.Aim(); } if (Input.GetButtonDown("Follow")) { cmdHdlr.FollowMe(); } if (Input.GetButtonDown("Move")) { cmdHdlr.MoveCommand(); } if (Input.GetButtonDown("Hold Fire")) { cmdHdlr.RulesOfEngagement(); } if (Input.GetButtonDown("Hold Position")) { cmdHdlr.HoldCommand(); } if (Input.GetButtonDown("Cmnd Sldr All")) { cmdHdlr.CommandSoldiers(CommandHandler.Soldiers.All); } if (Input.GetButtonDown("Cmnd Sldr 1")) { cmdHdlr.CommandSoldiers(CommandHandler.Soldiers.Soldier1); } if (Input.GetButtonDown("Cmnd Sldr 2")) { cmdHdlr.CommandSoldiers(CommandHandler.Soldiers.Soldier2); } if (Input.GetButtonDown("Cmnd Sldr 3")) { cmdHdlr.CommandSoldiers(CommandHandler.Soldiers.Soldier3); } } }