//trap countdown code IEnumerator TrapCountdown(s_parent_Trap.TRAPS trapType) { if (trapType == s_parent_Trap.TRAPS.SLOWDOWN) { yield return(new WaitForSeconds(sensitivityTrapCooldown)); currentLookSensitivity = lookSensitivity; trapMovementMultiplier = 1; hitByTrapParticle.SetActive(false); } /* * /* ================ STOP TRAPS ================ * * else if (trapType == s_parent_Trap.TRAPS.STOP) * { * walkSpeed = 0f; * //myRb.isKinematic = true; * yield return new WaitForSeconds(3); * //myRb.isKinematic = false; * walkSpeed = 10f; * } * * */ else { yield return(null); } isTrapped[selectedTrapIndex] = false; }
//TRAP CODE FOLLOWS /* trigger the trap of type -- trap type * trapType: * 0 - Decoy trap * 1 - Slowdown trap * 2 - Stay still trap */ public void TriggerTrap(s_parent_Trap.TRAPS trapType) { if (trapType == s_parent_Trap.TRAPS.DECOY) { return; } else if (trapType == s_parent_Trap.TRAPS.SLOWDOWN) { isTrapped[selectedTrapIndex] = true; currentLookSensitivity *= trapSlowDownMultiplier; trapMovementMultiplier = trapSlowDownMultiplier; hitByTrapParticle.SetActive(true); StartCoroutine(TrapCountdown(trapType)); } /* ================ STOP TRAPS ================ * * * else if (trapType == s_parent_Trap.TRAPS.STOP) * { * isTrapped[selectedTrapIndex] = true; * StartCoroutine(TrapCountdown(trapType)); * } * * */ }
void Update() { //Set jump = true for next call to FixedUpdate() to make the character jump //Can't check for ButtonDown in FixedUpdate because it can run multiple times a single frame, making jump become inconsistent if (Input.GetButtonDown("Jump" + suffix) && IsGrounded()) { isJumping = true; myAnimator.SetLayerWeight(1, 1.0f); myAnimator.SetTrigger("Jump"); } if (isHacking) { if (timeToResetHack >= 0) { timeToResetHack -= Time.deltaTime; ui_timerImage.fillAmount = timeToResetHack / hackCooldownTime; } if (timeToResetHack <= 0) { timeToResetHack = hackCooldownTime; isHacking = false; ui_timerImage.fillAmount = 1f; if (hackedEnemy) { hackedEnemy = false; //s_gameManager.Instance.HackEnemy((2 - playerNumber) + 1, 1); } else if (hasMirroredSelf) { UseMirror(true); hasMirroredSelf = false; } else if (hasBlackoutSelf) { UseBlackout(true); hasBlackoutSelf = false; } } } //handle glitchy-ness if (isGlitched) { float currDistance = s_roundManager.Instance.GetPlayerDistance(); float glitchVal = 1 - Mathf.Pow(currDistance, 3) / Mathf.Pow(enemyBlackoutRange, 3); //exponential curve math function to determine amount of blackout, normalized between 0 and 1 glitchVal = Mathf.Clamp(glitchVal, 0, 1); //clamp it so it never goes beyond 1 -- extra precautionary measure blackout.CrossFadeAlpha(glitchVal, 0.1f, true); } // handle trap drop input // scrollAxisInUse - use this to reset the scroll axis input to 0 once there is no input if (Input.GetAxisRaw("TrapScroll" + suffix) == 1f && availableTraps.Count > 0 && !scrollAxisInUse) { scrollAxisInUse = true; if (availableTraps.Count > 1) { if (selectedTrapIndex + 1 < availableTraps.Count) { selectedTrapIndex++; } else { selectedTrapIndex = 1; } selectedTrap = availableTraps[selectedTrapIndex]; ui_currTrap.text = "Selected trap: " + selectedTrap; //Debug.Log("Current trap: " + selectedTrap + " num: " + nSelectedTrap[selectedTrapIndex]); } } if (Input.GetAxisRaw("TrapScroll" + suffix) == -1f && availableTraps.Count > 0 && !scrollAxisInUse) { scrollAxisInUse = true; if (availableTraps.Count > 1) { if (selectedTrapIndex - 1 > 0) { selectedTrapIndex--; } else { selectedTrapIndex = availableTraps.Count - 1; } selectedTrap = availableTraps[selectedTrapIndex]; ui_currTrap.text = "Selected trap: " + selectedTrap; //Debug.Log("Current trap: " + selectedTrap); } } //reset scroll axis in use if (Input.GetAxisRaw("TrapScroll" + suffix) == 0 && scrollAxisInUse) { scrollAxisInUse = false; } if ((Input.GetAxisRaw("Drop" + suffix) <= -0.3f || Input.GetAxisRaw("Drop" + suffix) >= 0.3f) && !canThrow) { //Debug.Log("Trap dropped"); //trapAxisInUse = true; if (selectedTrapIndex > 0) { canThrow = true; ui_crosshair.SetBool("aim", false); myAnimator.SetLayerWeight(2, 1.0f); myAnimator.SetTrigger("Aim"); handTrap.SetActive(true); } } if ((Input.GetAxisRaw("Drop" + suffix) > -0.3f && Input.GetAxisRaw("Drop" + suffix) <= 0.3f) && canThrow) { canThrow = false; ui_crosshair.SetBool("aim", true); //myAnimator.SetLayerWeight(2, 0.0f); DropTrap(); } //handle taking flag if (canTakeFlag) { if (Input.GetButton("Capture" + suffix)) { if (!ui_progressSlider.gameObject.activeSelf) { ui_progressSlider.gameObject.SetActive(true); } if (timeToTakeFlag <= flagHoldTimer) { timeToTakeFlag += Time.deltaTime; ui_progressSlider.value = timeToTakeFlag / flagHoldTimer; } else { hasEnemyFlag = true; canTakeFlag = false; Debug.Log(suffix + " flag taken"); s_roundManager.Instance.SetWinner(playerNumber); /* * This is for getting back to base. Don't delete it just in case we need it again. * * s_roundManager.Instance.RemoveFlag((2 - playerNumber) + 1); * ui_prompt.gameObject.SetActive(false); * ui_progressSlider.gameObject.SetActive(false); * ui_flagStatus.gameObject.SetActive(true); * ui_flagStatus.text = "Data retrieved.\nHead back to base."; * StartCoroutine(DeactivateFlagUI());*/ } } else { timeToTakeFlag = 0; ui_progressSlider.value = 0; if (ui_progressSlider.gameObject.activeSelf) { ui_progressSlider.gameObject.SetActive(false); } } } if (!isHacking) { if (Input.GetButtonDown("UseMirror" + suffix)) { UseMirror(false); isHacking = true; } if (Input.GetButtonDown("UseBlackout" + suffix) && s_roundManager.Instance.GetPlayerDistance() < enemyBlackoutRange) { UseBlackout(false); isHacking = true; } } /* * ================ HACK SELECTION AND SELF HACK. ONLY REMOVE WHEN CONFIRMED THAT WE DON'T WANT THIS FEATURE ================ * * // handle hack (ability) selection input * // hackAxisInUse - bool to check whether there is any hack scrolling input from the player * // this is necessary because without the bool the axis will never reset to 0 * if (Input.GetAxisRaw("Ability" + suffix) == 1f && !hackAxisInUse) * { * hackAxisInUse = true; * selectedAbility = 1; * //Debug.Log("AbilityUp"); * } * if (Input.GetAxisRaw("Ability" + suffix) == -1f && !hackAxisInUse) * { * hackAxisInUse = true; * selectedAbility = 2; * //Debug.Log("AbilityDown"); * } * //reset hackAxisInUse to 0 once there is no input * if (Input.GetAxisRaw("Ability" + suffix) == 0f && hackAxisInUse) * { * hackAxisInUse = false; * } * * //handle hack (ability) use input * if (Input.GetButtonDown("UseOnSelf" + suffix)) * { * //Debug.Log("UseSelf"); * if (selectedAbility == 1) * { * if (hasMirroredSelf || !isHacking) * { * UseMirror(true); * isHacking = true; * hasMirroredSelf = !hasMirroredSelf; * } * } * else if (selectedAbility == 2) * { * if (hasBlackoutSelf || !isHacking) * { * UseBlackout(true); * isHacking = true; * hasBlackoutSelf = !hasBlackoutSelf; * } * } * } * if (Input.GetButtonDown("UseOnEnemy" + suffix) && !isHacking) * { * hackedEnemy = true; * //Debug.Log("UseEnemy"); * if (selectedAbility == 1) * { * UseMirror(false); * isHacking = true; * } * else if (selectedAbility == 2 && s_roundManager.Instance.GetPlayerDistance() <= enemyBlackoutRange) * { * UseBlackout(false); * isHacking = true; * } * else * { * Debug.Log("Enemy Too Far!!"); * } * } * * */ }
//TRAP DROPPING CODE FOLLOWS private void DropTrap() { /*if (nDeployedTraps >= maxDeployableTraps) * { * Debug.Log("MAX POSSIBLE TRAPS DEPLOYED"); * return; * }*/ if (nSelectedTrap[selectedTrapIndex] > 0) { float offset = 0.7f; GameObject trap = null; // = Instantiate(traps[selectedTrap], myCam.transform.position + myCam.transform.forward * offset, Quaternion.identity) as GameObject; if (selectedTrap != s_parent_Trap.TRAPS.DECOY) { trap = Instantiate(traps[selectedTrap], trapSpawnPoint.transform.position /* + myCam.transform.forward * offset */, Quaternion.identity) as GameObject; trap.GetComponent <Rigidbody>().AddForce(myCam.transform.forward * throwForce); trap.GetComponent <s_parent_Trap>().SetOwner(playerNumber); } if (selectedTrap == s_parent_Trap.TRAPS.DECOY) { trap = Instantiate(traps[selectedTrap], decoySpawnLocation.transform.position, decoySpawnLocation.transform.rotation) as GameObject; //trap.transform.Rotate(0, body.transform.rotation.y * 5, 0); trap.GetComponent <s_parent_Trap>().SetOwner(playerNumber); } //trap.GetComponent<s_parent_Trap>().SetOwner(playerNumber); handTrap.SetActive(false); myAnimator.SetTrigger("Throw"); StartCoroutine(ResetAnimatorLayerWeight()); nSelectedTrap[selectedTrapIndex]--; switch (selectedTrap) { case s_parent_Trap.TRAPS.DECOY: ui_nTraps[0].text = "Decoys: " + nSelectedTrap[selectedTrapIndex]; break; case s_parent_Trap.TRAPS.SLOWDOWN: ui_nTraps[1].text = "Slowdowns: " + nSelectedTrap[selectedTrapIndex]; break; /* ================ STOP TRAPS ================ * * * case s_parent_Trap.TRAPS.STOP: * ui_nTraps[2].text = "Stop Traps: " + nSelectedTrap[selectedTrapIndex]; * break; * * */ } if (nSelectedTrap[selectedTrapIndex] <= 0) { nSelectedTrap.RemoveAt(selectedTrapIndex); availableTraps.RemoveAt(selectedTrapIndex); if (availableTraps.Count > selectedTrapIndex + 1) { selectedTrapIndex++; } else { selectedTrapIndex = availableTraps.Count - 1; } selectedTrap = availableTraps[selectedTrapIndex]; ui_currTrap.text = "Selected trap: " + selectedTrap; } //ui_nTraps[selectedTrapIndex].text = (selectedTrap==0 ? "Decoys: ":"Slowdowns: ") + nSelectedTrap[selectedTrapIndex]; nDeployedTraps++; if (nDeployedTraps <= maxDeployableTraps) { fieldTraps.Enqueue(trap.gameObject); // Add trap at end of queue } else { Destroy(fieldTraps.Peek().gameObject); // Destroy trap at start of queue fieldTraps.Dequeue(); // Pop the queue } ui_totalTraps.text = "Total traps on field: " + nDeployedTraps; } }
public virtual void SetTrapType(s_parent_Trap.TRAPS type) { trapType = type; }