/// <summary> /// Updates the destination if it has changed since the last time. /// </summary> private void UpdateDestination() { if (lastType != moveType) { DetermineDestination(); } lastType = moveType; }
// Start is called before the first frame update protected virtual void Start() { health = GetComponent <HealthBehavior>(); health.setHealth(maxHealth); shooter = GetComponent <MinionShootController>(); anim = GetComponent <Animator>(); leftRight = getAxisString(true); upDown = getAxisString(false); altHalt = getAltHalt(); // Set base information if (P1_Base == null) { P1_Base = GameObject.FindWithTag("P1_Base"); } if (P2_Base == null) { P2_Base = GameObject.FindWithTag("P2_Base"); } Assert.IsTrue(taggyboi.isMinion(tag), "Minion tag " + tag + " improperly set"); homeBase = (taggyboi.isP1Tag(tag) ? P1_Base.transform : P2_Base.transform); enemyBase = (taggyboi.isP1Tag(tag) ? P2_Base.transform : P1_Base.transform); // Start them off by standing still until they get an order. moveType = lastType = MinionMoveTypes.Halt; // Both Soldiers and Teddies are allowed to start moving immediately State = MinionStates.Move; StartCoroutine(TargetSearch()); if (debugOnce) { //StartCoroutine(PrintStates()); //StartCoroutine(PrintDpad()); debugOnce = false; } }
// Update is called once per frame protected virtual void Update() { if (!nv_agent.isActiveAndEnabled) { return; } if (!health.isNotDead()) { Die(); } if (CanAttack()) { State = MinionStates.Attack; Attack(); } if (doNavMeshDemo) { // NavMeshDemo with mouse controls if (useMouseControls) { #region Mouse Controls // Both mouse buttons = stay if (Input.GetKey(KeyCode.Mouse0) && Input.GetKey(KeyCode.Mouse1)) { moveType = MinionMoveTypes.Halt; } // Right mouse button = attack else if (Input.GetKeyDown(KeyCode.Mouse1)) { moveType = MinionMoveTypes.Attack; } // Left mouse button = defend else if (Input.GetKeyDown(KeyCode.Mouse0)) { moveType = MinionMoveTypes.Defend; } #endregion } // NavMeshDemo with pad controls else { #region Pad Controls // If down, defend if (Input.GetAxisRaw(upDown) < 0) { //Debug.Log("Attempting to change move type to DEFEND"); moveType = MinionMoveTypes.Defend; } // Else if up, attack else if (Input.GetAxisRaw(upDown) > 0) { //Debug.Log("Attempting to change move type to ATTACK"); moveType = MinionMoveTypes.Attack; } // Else if right or altHalt button, halt else if ((useAltHalt && Input.GetButtonDown(altHalt)) || (!useAltHalt && Input.GetAxisRaw(leftRight) < 0)) { //Debug.Log("Attempting to change move type to HALT"); moveType = MinionMoveTypes.Halt; } #endregion } } else { //DebugMovement(); } UpdateDestination(); if (anim) { UpdateAnimator(); } }