private void OnTriggerStay(Collider other) { // Fire if (hazardState == HazardState.Ready) { hazardState = HazardState.Firing; } }
private void CoolDown() { if (timeStamp <= Time.time) { timeStamp = 0.0f; hazardState = HazardState.Ready; } }
private void RetractPiston() { if (transform.position == initialPosition) { hazardState = HazardState.Ready; } else { float maxDistanceStep = pistonTravelVector.magnitude / retractSteps; transform.position = Vector3.MoveTowards(transform.position, initialPosition, maxDistanceStep); } }
private void ExtendPiston() { Vector3 targetPosition = initialPosition + pistonTravelVector; if (transform.position == targetPosition) { hazardState = HazardState.CoolingDown; } else { float maxDistanceStep = pistonTravelVector.magnitude / extendSteps; transform.position = Vector3.MoveTowards(transform.position, targetPosition, maxDistanceStep); } }
private void RetractHammer() { Quaternion currentRotation = hammer.transform.rotation; if (IsSameRotation(currentRotation, initialRotation)) { timeStamp = Time.time + coolDownPeriodInSeconds; hazardState = HazardState.CoolingDown; } else { float maxStepDeltaDegrees = Mathf.Abs(fallAngle - initialRotation.eulerAngles.x) / rearmingSteps; hammer.transform.rotation = Quaternion.RotateTowards(currentRotation, initialRotation, maxStepDeltaDegrees); } }
private void FireHammer() { Quaternion currentRotation = hammer.transform.rotation; Quaternion targetRotation = Quaternion.Euler(new Vector3(fallAngle, initialRotation.eulerAngles.y, initialRotation.eulerAngles.z)); if (IsSameRotation(currentRotation, targetRotation)) { hazardState = HazardState.Rearming; } else { float maxStepDeltaDegrees = Mathf.Abs(fallAngle - initialRotation.eulerAngles.x) / fallSteps; hammer.transform.rotation = Quaternion.RotateTowards(currentRotation, targetRotation, maxStepDeltaDegrees); } }
private void OnCollisionEnter(Collision collision) { if (hazardState != HazardState.Firing) { return; } CreatePhysicalImpact(collision); PlayHammerHitSound(); if (damageDealer) { damageDealer.DealDamage(collision.gameObject, damageAmount, false); } hazardState = HazardState.Rearming; }
void StateHandler() { switch (trapState) { case HazardState.Idle: if (tick > idleTime * 50) { trapState = HazardState.Warning; tick = 0; WarningTransition(); } break; case HazardState.Warning: if (tick > warningTime * 50) { trapState = HazardState.Active; tick = 0; ActiveTransition(); } break; case HazardState.Active: if (tick > activeTime * 50) { trapState = HazardState.Cooldown; tick = 0; CooldownTransition(); } break; case HazardState.Cooldown: if (tick > cooldownTimer * 50) { trapState = HazardState.Idle; tick = 0; IdleTransition(); } break; } }
private void Fire() { hazardState = HazardState.Firing; }