IEnumerator StateSwitch(float timeTillStateChange) { timeTillStateChange = Random.Range(0, maxTimeBetweenStates); currentRunTime += Time.deltaTime; if (bossStage == BossStages.Stage1) { if (currentRunTime <= timeTillStateChange && damageDealt) { currentRunTime += attackProbabilityBooster; //does not attack, raise probability nothing happens } else if (currentRunTime >= timeTillStateChange) { Stage1CurrentState = S1BossStates.S1Attacking; //attacks, repeat } } else if (bossStage == BossStages.Stage2) { if (currentRunTime <= timeTillStateChange && damageDealt) { currentRunTime += attackProbabilityBooster; //does not attack, raise probability nothing happens } else if (timeTillStateChange >= currentRunTime) { Stage2CurrentState = S2BossStates.S2Attacking; //attacks, repeat } } yield return(null); }
IEnumerator SlamAttack() { isSlamming = true; isTrackingPlayerPosition = false; timeHoldingSlam = 0; while (true) { anim.SetBool("SlamAttack", true); timeHoldingSlam += Time.deltaTime; if (timeHoldingSlam >= timeToHoldSlam) // If Kali has held long enough... { if (activeSlamSide == rightMapDetectionCollider) { slamRightCollider.gameObject.SetActive(true); slamLeftCollider.gameObject.SetActive(false); } if (activeSlamSide == leftMapDetectionCollider) { slamLeftCollider.gameObject.SetActive(true); slamRightCollider.gameObject.SetActive(false); } anim.SetBool("SlamAttack", false); currentPlayerActiveSideCollider.SendMessage("Slamming"); Stage1CurrentState = S1BossStates.S1Idle; Stage2CurrentState = S2BossStates.S2Idle; isTrackingPlayerPosition = true; isSlamming = false; yield return(new WaitForSeconds(2)); slamLeftCollider.gameObject.SetActive(false); slamRightCollider.gameObject.SetActive(false); yield break; //...stop the coroutine } yield return(null); // Otherwise, continue next frame } }
IEnumerator SweepAttack() { isSweeping = true; timeHoldingSweep = 0f; float timeSinceStarted = 0f; while (true) { timeHoldingSweep += Time.deltaTime; anim.SetBool("SweepAttack", true); if (timeHoldingSweep >= timeToHoldSweep) { timeSinceStarted += Time.deltaTime; transform.position = Vector3.Lerp(transform.position, sweepEndPosition.position, timeSinceStarted * 0.5f); if (transform.position == sweepEndPosition.position) // If the object has arrived... { transform.position = Vector3.Lerp(transform.position, kaliBasePosition.position, 1f); if (transform.position == kaliBasePosition.position) { anim.SetBool("SweepAttack", false); currentPlayerActiveSideCollider.SendMessage("Sweeping"); Stage2CurrentState = S2BossStates.S2Idle; isTrackingPlayerPosition = true; isSweeping = false; yield break; //...stop the coroutine } yield return(null); } yield return(null); // Otherwise, continue next frame } yield return(null); } }
void RandomizeAttacks() { int whichAttack = Random.Range(0, 3); Debug.Log("I'm attacking with " + whichAttack); if (whichAttack == 0) { StartCoroutine(SlamAttack()); } if (whichAttack == 1) { StartCoroutine(MoveToSweepAttackLocation()); } if (whichAttack == 2) { StartCoroutine(LaserEyeBeam()); } Stage2CurrentState = S2BossStates.S2Idle; }
public IEnumerator LaserEyeBeam() { isTrackingPlayerPosition = false; timeHoldingLaser = 0; float sqrRemainingDistanceToDestination = (laserHitPosition.transform.position - laserEndPosition.transform.position).sqrMagnitude; float timeSinceStarted = 0f; while (true) { timeHoldingLaser += Time.deltaTime; anim.SetBool("LaserAttack", true); if (timeHoldingLaser >= timeToHoldLaser) { laserBeam.enabled = true; usingLaser = true; timeSinceStarted += Time.deltaTime; RaycastHit2D hit = Physics2D.Raycast(laserSpawnPosition.transform.position, laserHitPosition.transform.position); Debug.DrawRay(laserSpawnPosition.transform.position, laserHitPosition.transform.position, Color.green); if (hit.collider) { Debug.Log("I hit " + hit.collider.name); if (hit.collider.tag == "Player") { Debug.Log("Have touched the player"); //laserHitPosition.transform.position = new Vector3(hit.point.x, hit.point.y); } if (hit.collider.tag == "Obstacle") { Debug.Log("I hit " + hit.collider.name); } if (hit.collider.tag == "Enemy") { Debug.Log("I hit " + hit.collider.name); } } laserHitPosition.transform.position = laserStartPosition.transform.position; laserHitPosition.transform.position = Vector3.Lerp(laserStartPosition.transform.position, laserEndPosition.transform.position, timeSinceStarted); laserBeam.SetPosition(0, laserSpawnPosition.transform.position); //defines 1st ("start") point laserBeam.SetPosition(1, laserHitPosition.transform.position); //defines 2nd (or "end") point if (laserHitPosition.transform.position == laserEndPosition.transform.position) // If the object has arrived... { anim.SetBool("LaserAttack", false); usingLaser = false; laserBeam.enabled = false; isTrackingPlayerPosition = true; Stage2CurrentState = S2BossStates.S2Idle; yield break; //...stop the coroutine } yield return(null); // Otherwise, continue next frame } yield return(null); } }