public void MakeSound() { if (this.gameObject.CompareTag ("Bottle") || this.gameObject.CompareTag ("Jar")) { //brokenObject = (GameObject)Instantiate(brokenSphere, this.transform.position, Quaternion.identity); //newSphere = (GameObject)Instantiate(Sphere, this.transform.position, Quaternion.identity); if (newSphere != null) { if (newSphere.activeInHierarchy == false) { newSphere.SetActive(true); } } else { newSphere = (GameObject)Instantiate(Sphere, this.transform.position, Quaternion.identity); } newSphere.transform.position = brokenPieces.transform.position; newSphere.transform.Rotate (Vector3.zero); sphereScript = newSphere.GetComponent<soundSphere>(); sphereScript.setMaxDiameter(maxScale); //destroySelf(); } else if (this.gameObject.CompareTag ("Glass")) { //brokenObject = (GameObject)Instantiate(brokenCube, this.transform.localPosition, Quaternion.identity); //newSphere = (GameObject)Instantiate(Sphere, this.transform.position, Quaternion.identity); if (newSphere.activeInHierarchy == false) { newSphere.SetActive(true); } newSphere.transform.position = brokenPieces.transform.position; sphereScript = newSphere.GetComponent<soundSphere>(); sphereScript.setMaxDiameter(maxScale); //destroySelf(); } // if (this.gameObject.CompareTag ("jar")) // { // brokenObject = (GameObject)Instantiate(brokenSphere, this.transform.position, Quaternion.identity); // newSphere = (GameObject)Instantiate(Sphere, this.transform.position, Quaternion.identity); // newSphere.transform.parent = brokenObject.transform; // sphereScript = newSphere.GetComponent<soundSphere>(); // sphereScript.setMaxDiameter(maxScale); // destroySelf(); // } }
// Update is called once per frame void Update() { switch (statesHunter) { case enumStatesHunter.chase: { //----------------------------------------------------------------------------// // chase the Player constantly searching for a waypoint at the Player position// //----------------------------------------------------------------------------// //--------------------------// //Leap Attack While Chasing // //--------------------------// if (vectorx < chargeRange || vectorz < chargeRange) { agent.autoBraking = false; enemyRotation = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z); transform.LookAt(enemyRotation); transform.position = Vector3.MoveTowards(transform.position, currentTarget.position, 5 * chaseSpeed / 6 * Time.deltaTime); leapTimer -= Time.deltaTime; if (leapTimer <= 0.0f) { agent.autoBraking = true; leapTimer = defaultLeapTimer; } } else { leapTimer -= Time.deltaTime; if (leapTimer <= 0.0f) { agent.autoBraking = true; leapTimer = defaultLeapTimer; } } // Bark While chasing if (barkTimer <= 0.0f) { newSphere = (GameObject)Instantiate(sphere, this.transform.position, Quaternion.identity); newSphere.transform.parent = transform; barkTimer = defaultBarkTimer; if (newSphere) { hunterSphereScript = newSphere.GetComponent<soundSphere>(); hunterSphereScript.setMaxDiameter(maxScale); } } barkTimer -= Time.deltaTime; // Escape from chase Physics.Linecast(transform.position, player.transform.position, out hit); if (hit.collider.CompareTag (player.GetComponent<Collider>().tag) == false) { escapeTimer -= Time.deltaTime; if (vectorx >= chaseRange || vectorz >= chaseRange) { agent.speed = patrolSpeed; if (alertArea[areaCounter] != null) { currentTarget = alertArea[areaCounter]; } areaCounter++; if (areaCounter > alertArea.Count - 1) { areaCounter = 0; } alertTimer = defaultAlertTimer; stateManager(3); } else if (escapeTimer <= 0.0f) { agent.speed = patrolSpeed; if (alertArea[areaCounter] != null) { currentTarget = alertArea[areaCounter]; } areaCounter++; if (areaCounter > alertArea.Count - 1) { areaCounter = 0; } alertTimer = defaultAlertTimer; stateManager(3); } } else { agent.speed = chaseSpeed; currentTarget = player.transform; escapeTimer = defaultEscapeTimer; } } break; // Look around a room by moving from waypoint to waypoint case enumStatesHunter.alert: { if (alertTimer <= 0.0f) { stateManager(4); } if (vectorx >= waypointOffsetMin && vectorx <= waypointOffsetMax && vectorz >= waypointOffsetMin && vectorz <= waypointOffsetMax) { if (timer <= 0.0f) { if (alertArea[areaCounter] != null) { currentTarget = alertArea[areaCounter]; } areaCounter++; if (areaCounter > alertArea.Count - 1) { areaCounter = 0; } if (tempcounters < 6) { if (turnCounter != 0) { turnCounter = 0; } if (idleTimer != defaultIdleTimer) { idleTimer = defaultIdleTimer; } tempcounters++; stateManager(4); } } } } break; // Stand on the spot and look at preset directions case enumStatesHunter.idleSuspicious: { if (alertTimer > 0) { alertTimer -= Time.deltaTime; } else if (alertTimer <= 0) { alertTimer = 0; stateManager(5); } if (turnCounter < 3) { currentTargetDirection = directionDegrees[0]; rotateEnemy(currentTargetDirection, rotationStep); if (rotationCompleted) { directionDegrees.Add(directionDegrees[0]); directionDegrees.Remove(directionDegrees[0]); rotationCompleted = false; turnCounter++; turnTimer += defaultTurnTimer * Time.deltaTime; } } else //if (turnCounter > 2) { //alertTimer = defaultAlertTimer; turnCounter = 0; stateManager(3); } idleTimer -= Time.deltaTime; } break; // Return to the spawner and destroy self case enumStatesHunter.returnToSpawner: { currentTarget = transform.parent; if(vectorx >= waypointOffsetMin && vectorx <= waypointOffsetMax && vectorz >= waypointOffsetMin && vectorz <= waypointOffsetMax) { selfDestruct(); } } break; default: break; } if (currentTarget != null) { vectorTransformPositionx = transform.position.x; vectorTransformPositionz = transform.position.z; vectorCurrentTargetx = currentTarget.position.x; vectorCurrentTargetz = currentTarget.position.z; vectorx = (vectorTransformPositionx - vectorCurrentTargetx); vectorz = (vectorTransformPositionz - vectorCurrentTargetz); if (vectorz < 0) { vectorz *= -1; } if (vectorx < 0) { vectorx *= -1; } } if (timer <= 0.0f) { timer += defaultTimer; if (statesHunter != enumStatesHunter.idleSuspicious) { if (agent.destination != null) { agent.SetDestination(currentTarget.position); } } } timer -= Time.deltaTime; }
//======================================================================// // Barking is called in chase state // //======================================================================// void bark() { if (newSphere != null) { newSphere.SetActive (true); } else { newSphere = (GameObject)Instantiate (sphere, this.transform.position, Quaternion.identity); } newSphere.transform.parent = transform; newSphere.tag = "SoundSphere"; barkTimer = defaultBarkTimer; if (newSphere) { sphereScript = newSphere.GetComponent<soundSphere>(); sphereScript.setMaxDiameter(maxScale); } }
void Update() { //Velocity meter for the animator guy to see enemies actual speed currentMove = transform.position - previousPosition; currentSpeed = currentMove.magnitude / Time.deltaTime; previousPosition = transform.position; patrolAnim.speed = agent.speed * animationSpeedModifier; updateAnimator(); //Tried to make enemies be able to dodge each other when pahtfinding //Physics.Raycast(transform.position,transform.forward * 0.05f,out hit); //if (hit.collider.tag == "enemy" || hit.collider.tag == "fatDog" || hit.collider.tag == "huntingDog") //{ // dodge(hit.collider); //} //if (dodgeTimer <= 0 && dodging == true) //{ // dodging = false; // currentTarget = lastTarget; //} // To prevent opponent from sleeping rb.WakeUp(); // FSM switch (States) { // Patrol, moves from one waypoint to the next waiting for a second before advancing forward case enumStates.patrol: { if(!isPatrolling) { isPatrolling = true; } if (newTargetTimer >= 0) { agent.velocity = Vector3.zero; newTargetTimer -= Time.deltaTime; } else { patrolAnim.SetBool("patrolRun", false); if (agentStopped == true && isPaired) { agentStopped = false; agent.Resume(); } //Check if the player is within offset range from the current target if (vectorx >= waypointOffsetMin && vectorx <= waypointOffsetMax && vectorz >= waypointOffsetMin && vectorz <= waypointOffsetMax) { stateManager((int)enumStates.idle); onWaypoint = true; if (agentStopped == false) { agentStopped = true; agent.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.velocity = Vector3.zero; agent.Stop(); //isOnWaypoint = true; // patrolAnim.SetBool("patrolWalk", false); patrolAnim.SetBool("patrolRun", false); } } if (SeekForSmellSource) { tempSmellPosition = player.transform; stateManager((int)enumStates.smell); } } } break; // Idle, look around, without moving towards waypoints case enumStates.idle: { patrolAnim.SetBool("patrolRun", false); if (agentStopped == false) { agentStopped = true; agent.velocity = Vector3.zero; rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; agent.Stop(); } //Check if the player is within offset range from the current target if (vectorx >= waypointOffsetMin && vectorx <= waypointOffsetMax && vectorz >= waypointOffsetMin && vectorz <= waypointOffsetMax) { if (idleTimer <= 0) { if (currentTarget.gameObject.CompareTag ("Bone") == false) { lastTarget = currentTarget; } if (isPaired == true) { idleTimer = defaultIdleTimer; isOnWaypoint = true; } else if (isPaired == false) { idleTimer = defaultIdleTimer; currentTarget = targets[targetCounter]; stateManager(0); targetCounter++; if (targetCounter >= targets.Count) { targetCounter = 0; } } agent.speed = patrolSpeed; } idleTimer -= Time.deltaTime; if (idleTimer <= 0.0f) { idleTimer = 0.0f; } } //We assume enemy is not in a waypoint else { patrolAnim.SetBool("patrolRun", false); stateManager((int)enumStates.patrol); } if (SeekForSmellSource) { tempSmellPosition = player.transform; stateManager((int)enumStates.smell); } } break; // chase the Player constantly searching for a waypoint at the Player position// case enumStates.chase: { if (isPatrolling) { isPatrolling = false; } if(onWaypoint == true) { onWaypoint = false; } patrolAnim.SetBool("patrolRun", true); navPath = new NavMeshPath(); agent.CalculatePath(currentTarget.position, navPath); if (navPath.status == NavMeshPathStatus.PathPartial) { agent.autoBraking = false; enemyRotation = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z); transform.LookAt(enemyRotation); transform.position = Vector3.MoveTowards(transform.position, currentTarget.position, chaseSpeed * Time.deltaTime); // chargeTimer -= Time.deltaTime; // if (chargeTimer <= 0.0f) // { // agent.autoBraking = true; // chargeTimer = defaultChargeTimer; // } } if (vectorx < chargeRange || vectorz < chargeRange) { agent.autoBraking = false; enemyRotation = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z); transform.LookAt(enemyRotation); transform.position = Vector3.MoveTowards(transform.position, currentTarget.position, chaseSpeed * Time.deltaTime); } chargeTimer -= Time.deltaTime; if (chargeTimer <= 0.0f) { agent.autoBraking = true; chargeTimer = defaultChargeTimer; } // } // else // { // chargeTimer -= Time.deltaTime; // if (chargeTimer <= 0.0f) // { // agent.autoBraking = true; // chargeTimer = defaultChargeTimer; // } // } // Bark while chasing if (barkTimer < 0) { newSphere = (GameObject)Instantiate(sphere, this.transform.position, Quaternion.identity); newSphere.transform.parent = transform; newSphere.tag = "Sound"; barkTimer = defaultBarkTimer; if (newSphere) { sphereScript = newSphere.GetComponent<soundSphere>(); sphereScript.setMaxDiameter(maxScale); } } barkTimer -= Time.deltaTime; // Escape from chase Physics.Linecast(this.transform.position, player.transform.position, out hit); Debug.DrawLine(this.transform.position, player.transform.position, Color.red); if (hit.collider.CompareTag (playerCollider.tag) == false) { if (vectorx >= chaseRange || vectorz >= chaseRange) { agent.speed = patrolSpeed; if (alertArea[areaCounter] != null) { currentTarget = alertArea[areaCounter]; } areaCounter++; if (areaCounter > alertArea.Count - 1) { areaCounter = 0; } alertTimer = defaultAlertTimer; // organizeAlertWaypoints(); stateManager((int)enumStates.alert); } else if (escapeTimer <= 0) { agent.speed = patrolSpeed; if (alertArea[areaCounter] != null) { currentTarget = alertArea[areaCounter]; } areaCounter++; if (areaCounter > alertArea.Count - 1) { areaCounter = 0; } alertTimer = defaultAlertTimer; //organizeAlertWaypoints(); stateManager((int)enumStates.alert); } escapeTimer -= Time.deltaTime; } else { agent.speed = chaseSpeed; if (currentTarget != player.transform && currentTarget.CompareTag ("Bone") == false) { lastTarget = currentTarget; } currentTarget = player.transform; } } break; //Look around a room by moving from waypoint to waypoint// case enumStates.alert: { if (isPatrolling) { isPatrolling = false; } patrolAnim.SetBool("patrolRun", false); if (distracted) { stateManager((int)enumStates.distracted); } if (onWaypoint == true) { onWaypoint = false; } if (agentStopped == true) { agent.velocity = Vector3.zero; agentStopped = false; agent.Resume(); } if (alertTimer <= 0.0f) { if (lastTarget != null) { currentTarget = lastTarget; stateManager((int)enumStates.idleSuspicious); } } //Check if the player is within offset range from the current target if (vectorx >= waypointOffsetMin && vectorx <= waypointOffsetMax && vectorz >= waypointOffsetMin && vectorz <= waypointOffsetMax) { if (timer <= 0 && (!distracted)) { if (currentTarget != null && currentTarget.gameObject.CompareTag ("Bone") == false || currentTarget.gameObject.CompareTag ("Bottle") == false) { lastTarget = currentTarget; } //if(alertArea[areaCounter] == null) //{ // //areaCounter = 0; //} if (alertArea[areaCounter] != null) { currentTarget = alertArea[areaCounter]; } areaCounter++; if (areaCounter > alertArea.Count - 1) { areaCounter = 0; } if (tempcounters < 6) { if (turnCounter != 0) { turnCounter = 0; } if (idleTimer != defaultIdleTimer) { idleTimer = defaultIdleTimer; } tempcounters++; stateManager((int)enumStates.idleSuspicious); } } else { alertTimer -= Time.deltaTime; if (alertTimer <= 0.0f) { alertTimer = 0.0f; } } } else { alertTimer -= Time.deltaTime; if (alertTimer <= 0.0f) { alertTimer = 0.0f; } } if (SeekForSmellSource) { tempSmellPosition = player.transform; stateManager((int)enumStates.smell); } } break; case enumStates.idleSuspicious: { //-----------------------------------------------// //Stand on the spot and look at preset directions// //-----------------------------------------------// if (isPatrolling) { isPatrolling = false; } patrolAnim.SetBool("patrolRun", false); if (agentStopped == false) { agent.velocity = Vector3.zero; agentStopped = true; rb.angularVelocity = Vector3.zero; rb.velocity = Vector3.zero; agent.Stop(); } if (coneOfVisionScript.playerSeen == true) { agentStopped = false; agent.Resume(); stateManager((int)enumStates.chase); } if (alertTimer > 0.0f) { alertTimer -= Time.deltaTime; } if (alertTimer <= 0.0f) { alertTimer = 0.0f; // } // if (alertTimer <= 0) // { agent.speed = patrolSpeed; turnCounter = 0; agentStopped = false; agent.Resume(); stateManager((int)enumStates.patrol); } if (turnCounter < 3) { currentTargetDirection = directionDegrees[0]; rotateEnemy(currentTargetDirection, rotationStep); if (rotationCompleted) { directionDegrees.Add(directionDegrees[0]); directionDegrees.Remove(directionDegrees[0]); rotationCompleted = false; turnCounter++; turnTimer += defaultTurnTimer * Time.deltaTime; } } if (turnCounter > 2) { alertTimer = defaultAlertTimer; turnCounter = 0; agentStopped = false; agent.Resume(); stateManager((int)enumStates.alert); } idleTimer -= Time.deltaTime; if (idleTimer < 0.0f) { idleTimer = 0.0f; } } break; // Move towards distraction case enumStates.distracted: { if (isPatrolling) { isPatrolling = false; } patrolAnim.SetBool("patrolRun", false); distracted = true; Vector3 bonedir = (currentTarget.transform.localPosition) - (this.transform.localPosition); if (bonedir.x <= 4 && bonedir.x >= -4 && bonedir.z <= 4 && bonedir.z >= -4) { stateManager(7); distracted = false; if (!eatBone) { eatTimer = defaultEatTimer; } eatBone = true; } } break; case enumStates.detectSound: { if (soundSource != null) { if (soundSource.CompareTag ("Bone") || soundSource.CompareTag ("Bottle")) { if (isPatrolling) { isPatrolling = false; } navPath = new NavMeshPath(); NavMesh.CalculatePath(transform.position, soundSource.transform.position, NavMesh.AllAreas, navPath); if (navPath != null) { organizeAlertWaypoints(); patrolAnim.SetBool("patrolRun", false); if (soundSource.CompareTag ("Bone") == false || soundSource.CompareTag ("Bottle") == false && randomPointSelected == false) { if (RandomPoint(soundSource.transform.position, maxRange, out soundSourcePos)) { randomPointSelected = true; Debug.DrawRay(soundSourcePos, Vector3.up, Color.blue, 5.0f); tempWaypointPos = soundSource.transform; currentTarget = tempWaypointPos;//soundSourcePos; } } else if (soundSource.CompareTag ("Bone") || soundSource.CompareTag ("Bottle")) { currentTarget = soundSource.transform; } // agent.SetDestination(currentTarget.transform.position); // When sound is heard, move towards the source// // Check if the enemy is within offset range from the current target if (vectorx >= (waypointOffsetMin) && vectorx <= (waypointOffsetMax) && vectorz >= (waypointOffsetMin) && vectorz <= (waypointOffsetMax)) { if (soundSource != null || !soundSource.Equals(null)) { //Physics.Linecast(this.transform.position, soundSource.transform.position, out hit); //Debug.DrawLine(this.transform.position, soundSource.transform.position, Color.blue); } alertTimer = defaultAlertTimer; if (soundSource)//(hit.collider != null) { if (agentStopped == false) { agent.velocity = Vector3.zero; agentStopped = true; agent.Stop(); rb.angularVelocity = Vector3.zero; rb.velocity = Vector3.zero; } if (soundSource.CompareTag ("Bone"))//(hit.collider.tag == "bone") { randomPointSelected = false; soundSource = null; stateManager((int)enumStates.eatBone); } else { randomPointSelected = false; soundSource = null; stateManager((int)enumStates.alert); } } else { randomPointSelected = false; stateManager((int)enumStates.alert); } } else if (soundSource == null) { stateManager((int)enumStates.alert); } } else { stateManager((int)enumStates.alert); } } else if (soundSource.CompareTag ("Bone")) { // if (smellDetectedBefore) // { // continue towards the soundsource // but change target if the enemy // }smell // else // { // pick this as a new sound // } } } else if (soundSource == null || soundSource.activeInHierarchy == false) { stateManager ((int)enumStates.idle); } } break; // holds the enemy still for long enough for the distraction to pass case enumStates.eatBone: { if (isPatrolling) { isPatrolling = false; } patrolAnim.SetBool("patrolRun", false); if (soundSource != null && soundSource.CompareTag ("Bone")) { bone = soundSource; } //if (hit.collider.tag == "bone") //{ eatBone = true; if (!bone) { eatBone = true; alertTimer += defaultAlertTimer; stateManager((int)enumStates.alert); eatTimer = defaultEatTimer; currentTarget = alertArea[areaCounter]; } if (eatTimer <= 0) { eatTimer = defaultEatTimer; distracted = false; eatBone = false; currentTarget = alertArea[areaCounter]; breakableObject boneScript = bone.GetComponent<breakableObject>(); boneScript.destroySelf(); //Destroy(bone); alertTimer += defaultAlertTimer; stateManager((int)enumStates.alert); } eatTimer -= Time.deltaTime; if (eatTimer <= 0.0f) { eatTimer = 0.0f; } //} } break; // Smell if player smell collides with it case enumStates.smell: { if (smellTimer > 0.0f) { smellTimer -= Time.deltaTime; if (smellTimer <= 0.0f) { smellTimer = 180; stateManager((int)enumStates.idle); } patrolAnim.SetBool("patrolRun", false); // Turns enemy towards player's last known location// SeekForSmellSource = true; agentStopped = true; agent.velocity = Vector3.zero; agent.Stop(); rb.angularVelocity = Vector3.zero; rb.velocity = Vector3.zero; if (tempSmellPosition != null) { // Rotate the enemy Vector3 relative = transform.InverseTransformPoint(tempSmellPosition.position); float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg; transform.Rotate(0, angle * Time.deltaTime * rotationSpeed, 0); // If reach the angle if (angle < 5.0f && angle > -5.0f) { SeekForSmellSource = false; stateManager((int)enumStates.idle); } else { } } //else //{ // smellTimer = 180; // agentStopped = false; // agent.Resume(); // stateManager(1); //} } else { smellTimer = 180; stateManager((int)enumStates.idle); } } break; case enumStates.trapped: { // Stop the AI agentStopped = true; agent.velocity = Vector3.zero; agent.Stop (); rb.angularVelocity = Vector3.zero; rb.velocity = Vector3.zero; // Disable the vision coneOfVisionScript.enabled = false; } break; default: break; } // Calculating the distance between game object's target and this game object if (currentTarget != null) { // Vector calculations used multiple times during the update vectorTransformPositionx = transform.position.x; vectorTransformPositionz = transform.position.z; vectorCurrentTargetx = currentTarget.position.x; vectorCurrentTargetz = currentTarget.position.z; vectorx = (vectorTransformPositionx - vectorCurrentTargetx); vectorz = (vectorTransformPositionz - vectorCurrentTargetz); if (vectorz < 0) { vectorz *= -1; } if (vectorx < 0) { vectorx *= -1; } } // Checking if player is near enough to be smelled Vector3 direction = (player.transform.position - transform.position).normalized; Physics.Raycast(transform.position, direction, out hit, (ringOfSmellScript.radius)); Debug.DrawRay(transform.position, direction * ringOfSmellScript.radius, Color.yellow); if (hit.collider != null) { if (hit.collider.CompareTag (player.GetComponent<Collider>().tag)) { checkContinuousSmelling(player.transform.position); } else { turnTowardsSmellTimer = defaultTurnTowardsSmellTimer; } } else { turnTowardsSmellTimer = defaultTurnTowardsSmellTimer; } }
void Update() { //---------------------------------------------// // expands the sound sphere until maximum range// //---------------------------------------------// // if (this.gameObject.CompareTag ("Bone")) { // if (timer <= 0.0f) { // makeSound = false; // timer += defaultTimer; // newSphere = (GameObject)Instantiate (Sphere, this.transform.localPosition, Quaternion.identity); // newSphere.transform.parent = transform; // newSphere.tag = "Bone"; // sphereScript = newSphere.GetComponent<soundSphere> (); // sphereScript.setMaxDiameter (boneRadius); // expireTimer--; // } // timer -= Time.deltaTime; // } else if (this.gameObject.CompareTag ("BagOfAir")) { // if (timer <= 0) { // makeSound = false; // timer += defaultTimer; // newSphere = (GameObject)Instantiate (Sphere, this.transform.localPosition, Quaternion.identity); // newSphere.transform.parent = transform; // sphereScript = newSphere.GetComponent<soundSphere> (); // sphereScript.setMaxDiameter (boneRadius); // expireTimer--; // } // timer -= Time.deltaTime; // } if (gameObject.CompareTag ("Bone") || gameObject.CompareTag ("BagOfAir")) { if (timer <= 0.0f) { makeSound = false; timer += defaultTimer; if (newSphere == null) { newSphere = (GameObject)Instantiate (Sphere, this.transform.localPosition, Quaternion.identity); } else { newSphere.SetActive (true); } newSphere.transform.parent = transform; if (gameObject.CompareTag ("Bone")) { newSphere.tag = "Bone"; } else if (gameObject.CompareTag ("Bottle")) { newSphere.tag = "Bottle"; } sphereScript = newSphere.GetComponent<soundSphere> (); sphereScript.setMaxDiameter (boneRadius); } expireTimer -= Time.deltaTime; timer -= Time.deltaTime; } else { if (broken == true) { expireTimer -= Time.deltaTime; } } }