BuggySystem CheckHoldingControllers() { BuggySystem rhc = null; BuggySystem lhc = null; for (int i = 0; i < buggies.Length; i++) { if (Player.instance.rightHand.currentAttachedObject == buggies[i].controller.gameObject) { rhc = buggies[i]; } if (Player.instance.leftHand.currentAttachedObject == buggies[i].controller.gameObject) { lhc = buggies[i]; } } if (rhc != null && lhc != null) { return(rhc); // return right hand controller if holding with both hands. Safe guess. } else if (rhc != null) { return(rhc); } else if (lhc != null) { return(lhc); } else { return(null); } }
private void Start() { ResetAll(); checkpoints = checkpointContainer.GetComponentsInChildren <RaceCheckpoint>(); raceTitleInactive.text = trackName; raceTitleLeaderboard.text = trackName; // make a list of controllers and associated buggies BuggyControllerMoon[] controllers = FindObjectsOfType <BuggyControllerMoon>(); buggies = new BuggySystem[controllers.Length]; for (int i = 0; i < controllers.Length; i++) { buggies[i] = new BuggySystem(controllers[i], controllers[i].buggy); } }
private void Update() { Player player = Player.instance; if (state == RaceStates.Inactive) { inactiveTargetGO.SetActive(activeRace == null); if ((teleportPoint.transform.position - player.feetPositionGuess).sqrMagnitude < standingRadius) { if (!waitingForExit) // only start race if we're not waiting for the player to leave from a previous race { // player has teleported to race, begin. SwitchState(RaceStates.WaitingForBuggy); } } else { if (waitingForExit) { waitingForExit = false; } } } else { if ((teleportPoint.transform.position - player.feetPositionGuess).sqrMagnitude > standingRadius) { cancelTimer += Time.deltaTime; } else { cancelTimer = 0; } if (cancelTimer > 0.5f) { // player has teleported away from race, cancel. StopAllCoroutines(); SwitchState(RaceStates.Inactive); cancelTimer = 0; } } if (state == RaceStates.WaitingForBuggy) { BuggySystem holdingController = CheckHoldingControllers(); if (holdingController != null) { ActivateForBuggy(holdingController.buggy); } } if (state == RaceStates.WaitingForRace) { FreezeBuggy(); // activeCheckpoint = 0; //UpdateCheckpoints(); } if (state == RaceStates.Racing) { UpdateCheckpoints(); timer += Time.deltaTime; raceTimerText.text = LeaderboardManager.FormatMilliseconds(Mathf.RoundToInt(timer * 1000)); } if (state == RaceStates.Finished) { // highlight personal best if we just achieved it! raceFinishedPBText.highlighted = raceFinishedPBText.score == timescore; // highlight world record if we just achieved it! raceFinishedWRText.highlighted = raceFinishedWRText.score == timescore; } }