void FixedUpdate() { if (isShooting) { timeSpent += Time.deltaTime; switch (activeState) { case (SpikeState.launching): transform.position = Vector2.Lerp(Startpoint, Endpoint, timeSpent / launchTime); if (timeSpent >= launchTime) { activeState = SpikeState.resting; } break; case (SpikeState.resting): if (timeSpent >= launchTime + restTime) { activeState = SpikeState.returning; } break; case (SpikeState.returning): transform.position = Vector2.Lerp(Endpoint, Startpoint, (timeSpent - (launchTime + restTime)) / returnTime); if (timeSpent >= launchTime + restTime + returnTime) { activeState = SpikeState.ready; trigger.gameObject.SetActive(true); isShooting = false; } break; } } }
public void Lower() { if (State == SpikeState.Raised) { State = SpikeState.Lowering; } }
public void shoot() { GetComponentInChildren <Spike_trigger>().gameObject.SetActive(false); timeSpent = 0; if (shootSound) { AudioSource.PlayClipAtPoint(shootSound, Camera.main.transform.position); } switch (spikeDir) { case SpikeDir.down: Endpoint = Vector2.down * dist; break; case SpikeDir.up: Endpoint = Vector2.up * dist; break; case SpikeDir.left: Endpoint = Vector2.left * dist; break; case SpikeDir.right: Endpoint = Vector2.right * dist; break; } Endpoint += Startpoint; isShooting = true; activeState = SpikeState.launching; }
private void FixedUpdate() { if (State == SpikeState.Rising || State == SpikeState.Lowering) { Vector3 Start = State == SpikeState.Rising ? LoweredPosition : RaisedPosition; Vector3 End = State == SpikeState.Rising ? RaisedPosition : LoweredPosition; Vector3 lerped = Vector3.Lerp(Start, End, LerpTime * LerpTime); Quaternion StartRot = State == SpikeState.Rising ? LoweredRotation : RaisedRotation; Quaternion EndRot = State == SpikeState.Rising ? RaisedRotation : LoweredRotation; Quaternion lerpedRot = Quaternion.Lerp(StartRot, EndRot, LerpTime * LerpTime); LerpTime += Time.deltaTime * MovementSpeed; transform.position = lerped; transform.rotation = lerpedRot; Vector3 CurrentPos = transform.position; if (Vector3.Distance(CurrentPos, End) <= StateReachedThreshold) { transform.position = End; transform.rotation = EndRot; State = State == SpikeState.Rising ? SpikeState.Raised : SpikeState.Lowered; LerpTime = 0.0f; } } }
//Starts spikes public virtual void StartTell() { if (myState == SpikeState.NONE) { _currBound = _spikes.transform.localPosition + (Vector3.up * _tellDistance); myState = SpikeState.TELL; } }
/// <summary> /// Initialize variables, state and sounds /// </summary> void Start() { anticipationProgress = 0; riseProgress = 0; ignoreProgress = 0; state = SpikeState.hidden; animator = GetComponent <Animator>(); SoundManager.GetInstance().Load(anticipationClip); SoundManager.GetInstance().Load(riseClip); SoundManager.GetInstance().Load(descendClip); }
public void Rise() { if (State == SpikeState.Lowered) { State = SpikeState.Rising; SpikeTrigger spikeSound = GetComponent <SpikeTrigger>(); if (spikeSound != null) { spikeSound.TriggerSound(); } } }
//delay before the retreat protected virtual void StartRetreatDelay() { _currTime = (Time.time - _startTIme) / _attackDelayDuration; if (_currTime >= 1) { _currTime = 1; _currBound = _startPos; myState = SpikeState.RETREAT; } }
//delay inbetween the tell and attack protected virtual void StartAttackDelay() { _currTime = (Time.time - _startTIme) / _attackDelayDuration; if (_currTime >= 1) { _currTime = 1; _currBound = _spikes.transform.localPosition + (Vector3.up * _attackDistance); myState = SpikeState.ATTACK; } }
//stops the trap if room is finished public override void DisableTrap() { if (myState != SpikeState.NONE) { _startTIme = Time.time; myState = SpikeState.DONERETREAT; } else { myState = SpikeState.ROOMDONE; } }
//if the room finishes while the spikes are doing anything //spikes will retreat protected virtual void RoomDoneRetreat() { if (_spikes.transform.localPosition.y >= _currBound.y) { _spikes.transform.localPosition += Vector3.down * _retreatSpeed * Time.deltaTime; } else { _spikes.transform.localPosition = _startPos; myState = SpikeState.ROOMDONE; } }
//Does a tell for the spikes //spikes will come out of the holes but not deal damage protected virtual void DoTell() { if (_spikes.transform.localPosition.y <= _currBound.y) { _spikes.transform.localPosition += Vector3.up * _tellSpeed * Time.deltaTime; } else { _spikes.transform.localPosition = _currBound; _startTIme = Time.time; myState = SpikeState.ATTDELAY; } }
/// <summary> /// Evaluate trigger and damage other instance. /// </summary> /// <param name="col"></param> void OnTriggerStay(Collider col) { IDamagable other = null; TriggerSender ts = col.gameObject.GetComponent <TriggerSender>(); // Get IDamagable component on child or parent. if (ts != null) { other = ts.GetReciever().GetRecieverGameObject().GetComponent <IDamagable>(); } if (other == null) { other = col.gameObject.GetComponent <IDamagable>(); } // Check not null and other faction. if (other != null && (other.GetFaction() & targetFaction) != 0) { // Check state switch (state) { case SpikeState.hidden: { // Prepare spikes state = SpikeState.anticipated; anticipationProgress = 0; SoundManager.GetInstance().Play(anticipationClip); } break; case SpikeState.rised: { // Effect damage if (ignoreProgress == 0) { Vector3 proy = Vector3.ProjectOnPlane(col.gameObject.transform.position - transform.position, Vector3.up); int dir; if (Mathf.Abs(proy.z) > Mathf.Abs(proy.x)) { dir = proy.z > 0 ? 0 : 2; } else { dir = proy.x > 0 ? 3 : 1; } other.Damage(damage, dir, pushForce, stunForce); ignoreProgress = ignoreTime; } } break; } } }
//spike shoot up from the ground //damages the player if they are on top of the plates protected virtual void Attack() { if (_spikes.transform.localPosition.y <= _currBound.y) { _spikes.transform.localPosition += Vector3.up * _attackSpeed * Time.deltaTime; Vector3 _playerPos = _playerRef.transform.position; if (_playerPos.z < _topLeftCorner.z && _playerPos.x > _topLeftCorner.x && _playerPos.z > _bottomRightCorner.z && _playerPos.x < _bottomRightCorner.x) { _playerRef.TakeDamage(_trapDamage); } } else { _spikes.transform.localPosition = _currBound; _startTIme = Time.time; myState = SpikeState.RETDELAY; } }
/// <summary> /// Update spike state times /// </summary> void Update() { if (Time.timeScale > 0) { // Update spike state switch (state) { case SpikeState.hidden: break; case SpikeState.anticipated: anticipationProgress += Time.deltaTime; if (anticipationProgress >= anticipationTime) { state = SpikeState.rised; anticipationProgress = 0; SoundManager.GetInstance().Play(riseClip); } break; case SpikeState.rised: riseProgress += Time.deltaTime; if (riseProgress >= riseTime) { state = SpikeState.hidden; riseProgress = 0; SoundManager.GetInstance().Play(descendClip); } break; } // Update reactivation delay if (ignoreProgress != 0) { ignoreProgress = Mathf.Max(ignoreProgress - Time.deltaTime, 0); } animator.SetInteger("State", (int)state); } }
// Update is called once per frame void Update() { timer += Time.deltaTime; switch (state) { case SpikeState.Active: if (timer >= activeTime) { state = SpikeState.Inactive; gameObject.transform.Translate(new Vector2(0.0f, -yOffset)); timer = 0.0f; } break; case SpikeState.Inactive: if (timer >= inactiveTime) { state = SpikeState.Active; gameObject.transform.Translate(new Vector2(0.0f, yOffset)); timer = 0.0f; } break; } }
// Use this for initialization void Start() { activeState = SpikeState.ready; Startpoint = transform.position; trigger = GetComponentInChildren <Spike_trigger>(); }
//reset function public override void ResetTrap() { _spikes.transform.localPosition = _startPos; myState = SpikeState.NONE; }