/// <summary> /// Called when a computer randomly crashes /// </summary> private void crashComputer() { // Only allow waiting to crash computers to crash if (_state == ComputerState.WaitingToCrash || _state == ComputerState.RaptorCrashingComputer) { SetComputerColour(_state == ComputerState.WaitingToCrash ? Color.magenta : Color.yellow); _state = ComputerState.Crashed; if (linkedDoor != null) { linkedDoor.ReleaseTheRaptor(); } _crashTimer = CM.TimeFromCrashToExplode; _timerLength = _crashTimer; pBar.gameObject.SetActive(true); // Release the raptor (if it hasn't already been released and there is one associated with this computer if (currentRaptorUser != null) { currentRaptorUser.FindNewTarget(); currentRaptorUser._rState = RaptorAI.RaptorState.HeadingToTarget; currentRaptorUser = null; } } }
private void OnTriggerStay(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("Raptor")) { RaptorAI tmpRaptor = other.gameObject.GetComponent <RaptorAI> (); if (tmpRaptor.targettedComputer == this) { if (tmpRaptor._rState == RaptorAI.RaptorState.Content) { if (currentRaptorUser != null) { RaptorInterferenceInterferedWith(); } // Set up this computer to be happy forever but only if we haven't already done that. if (_state != ComputerState.RaptorSafelyUsingComputer) { TrainedRaptorAtComputer(); } } else { if (_state == ComputerState.WaitingToCrash) { RaptorVisitsComputer(other.gameObject.GetComponent <RaptorAI> ()); } else if (_state == ComputerState.Crashed) { other.gameObject.GetComponent <RaptorAI> ().FindNewTarget(); } } } } }
public void RaptorInterferenceInterferedWith() { _state = ComputerState.WaitingToCrash; pBar.progress = 0; pBar.gameObject.SetActive(false); currentRaptorUser = null; _crashTimer = Random.Range(CM.MinDefaultComputerCrashTime, CM.MaxDefaultComputerCrashTime); }
/// <summary> /// Called the moment a Raptor starts to interact with a computer and puts it on the shortcut to crashing /// </summary> private void RaptorVisitsComputer(RaptorAI raptor) { if (_state == ComputerState.WaitingToCrash) { _state = ComputerState.RaptorCrashingComputer; _crashTimer = CM.TimeToCrashWithRaptor; _timerLength = _crashTimer; pBar.gameObject.SetActive(true); raptor._rState = RaptorAI.RaptorState.FiddlingWithComputer; currentRaptorUser = raptor; computerSpeaker.PlayOneShot(CM.TypingSound); } }
private void OnTriggerEnter(Collider other) { // If we've already clicked on the computer before being in range if (other.gameObject.layer == LayerMask.NameToLayer("Player")) { if (other.gameObject.GetComponent <PlayerControl> ().targettedComputer == computerID) { if (_state == ComputerState.Crashed) { other.gameObject.GetComponent <PlayerControl> ().ShowComputerTools(); } } } else if (other.gameObject.layer == LayerMask.NameToLayer("Raptor")) { RaptorAI tmpRaptor = other.gameObject.GetComponent <RaptorAI> (); if (tmpRaptor.targettedComputer == this) { if (tmpRaptor._rState == RaptorAI.RaptorState.Content && _state != ComputerState.Exploding) { // Take permanent control of this computer. But not if computer has already exploded and we're in the few seconds wait for the game to end if (currentRaptorUser != null) { // There's another raptor at this computer already?? // Chase it away RaptorInterferenceInterferedWith(); } // Set up this computer to be happy forever TrainedRaptorAtComputer(); } else { if (_state == ComputerState.WaitingToCrash) { RaptorVisitsComputer(tmpRaptor); } else { // Computer crashed before the raptor could crash it, but after it targetted it tmpRaptor.FindNewTarget(); } } } } }
public void UseRaptorTool(int toolID) { int result = currentRaptor.Tooled(toolID); // Using the stick if (result == 0) { _pState = playerState.Moving; } else if (result == 1) // Training the raptor properly { _pState = playerState.TrainingRaptor; } else if (result == -1) // Not sure how we got here, but we did, so run away { _pState = playerState.Moving; currentRaptor = null; } HideRaptorTools(); }
// Update is called once per frame void Update() { bool PlayerHasInput = false; Ray rayToDestination = new Ray(); if (Input.touchCount > 0) { // Just look at the first touch that's been released and use it foreach (Touch iTouch in Input.touches) { if (iTouch.phase == TouchPhase.Ended) { PlayerHasInput = true; rayToDestination = Camera.main.ScreenPointToRay(iTouch.position); break; } } } if (Input.GetMouseButtonDown(0)) { rayToDestination = Camera.main.ScreenPointToRay(Input.mousePosition); PlayerHasInput = true; } if (PlayerHasInput) { RaycastHit rayResult; if (_pState == playerState.Moving) { if (Physics.Raycast(rayToDestination, out rayResult, 200f, ClickLayerMask)) { player.SetDestination(rayResult.point); if (rayResult.collider.gameObject.layer == LayerMask.NameToLayer("Computer")) { currentComputer = rayResult.collider.gameObject.GetComponent <Computer> (); targettedComputer = currentComputer.computerID; currentRaptor = null; if ((player.destination - player.gameObject.transform.position).magnitude < PlayerComputerInteraction) { if (currentComputer._state == Computer.ComputerState.Crashed) { ShowComputerTools(); } } } else if (rayResult.collider.gameObject.layer == LayerMask.NameToLayer("Raptor")) { targettedComputer = 0; currentComputer = null; currentRaptor = rayResult.collider.gameObject.GetComponent <RaptorAI> (); if ((player.destination - player.gameObject.transform.position).magnitude < PlayerComputerInteraction) { if (currentRaptor._rState == RaptorAI.RaptorState.FiddlingWithComputer) { ShowRaptorTools(); currentRaptor.playerInteracting = this; } } } else { targettedComputer = 0; currentComputer = null; currentRaptor = null; } } } } else if (_pState == playerState.Moving && currentRaptor != null) { if ((currentRaptor.gameObject.transform.position - this.gameObject.transform.position).sqrMagnitude < 4) { if (currentRaptor._rState == RaptorAI.RaptorState.FiddlingWithComputer) { ShowRaptorTools(); currentRaptor.playerInteracting = this; } } } }
public void LessonOver() { _pState = playerState.Moving; currentRaptor = null; }