public void EndHeavySwing() { weakSpot.SetWeakSpotActive(false); isMissileCooldown = false; time = 0; currentState = robotAction.idle; }
// Use this for initialization void Start() { currentState = robotAction.idle; isFacingLeft = true; isMissileCooldown = false; time = 0; weakSpot = GetComponentInChildren <WeakSpot>(); anim = GetComponent <Animator>(); }
//points in direction of the player when idle void eyesOnPlayer() { //face left if (player.transform.position.x < this.transform.position.x) { Vector3 scale = transform.localScale; if (scale.x >= 0f) { scale.x *= -1; } transform.localScale = scale; isFacingLeft = true; } //face right else { Vector3 scale = transform.localScale; if (scale.x < 0f) { scale.x *= -1; } transform.localScale = scale; isFacingLeft = false; } time += Time.deltaTime; //time to do the swinging animation if (time >= 8) { currentState = robotAction.swing; } //time to fire a missile else if (time >= 5 && !isMissileCooldown) { currentState = robotAction.missile; } }
//preps up missile void fireMissile() { if (!isMissileCooldown) { Rigidbody2D firedMissile; firedMissile = Instantiate(missile, this.transform.position, this.transform.rotation) as Rigidbody2D; //if robot is facing the left, barrage left if (isFacingLeft) { firedMissile.velocity = transform.TransformDirection(Vector3.left) * missileSpeed; } else //if the robot is facing right, barrage right { firedMissile.velocity = transform.TransformDirection(Vector3.right) * missileSpeed; } isMissileCooldown = true; } //reset back to idle state currentState = robotAction.idle; }