// Use this for initialization void Start() { clickDetect = GetComponent <ClickDetectScript>(); // Grab the click detection attached to this object holdDetect = GetComponent <HoldDetectScript>(); // Grab the hold detection attached to this object dataObject = GameObject.FindGameObjectWithTag("Timer"); //Grab the object that contains the data playerData = dataObject.GetComponent <PlayerDataScript>(); //Grab player data gameTimer = dataObject.GetComponent <GameTimerScript>(); //Grab timer data timeSpawned = gameTimer.timer; //Sync object timer to game time holdAnim = animHolder.GetComponent <Animator>(); feedbackAnimator = feedbackObject.GetComponent <Animator>(); feedbackExploAnimator = feedbackExploObject.GetComponent <Animator>(); //The following lines establish which level difficulty this button belongs to based on naming conventions //and then assigns the appropriate speedMod theSet = theParent.transform.parent.gameObject; theSetName = theSet.transform.name; if (theSetName != "GameManagerObject") { theSetValue = theSetName[5]; setNumber = int.Parse(theSetValue.ToString()); speedMod = speedMods[setNumber - 1]; } else { speedMod = 1f; } timeToDie *= speedMod; timeToClick *= speedMod; timeToHold *= speedMod; baseTimeForGood *= speedMod; holdAnim.speed = (1 / speedMod); }
// Update is called once per frame void Update() { //If we are in range then create bombs at postions that don't already have them. if (PlayerInRange(interactionRange, playerObject)) { //Show Help Text bombExplainText.SetActive(true); if (Input.GetKeyDown(respawnBombsKey)) { //See if a bomb exists GameObject bombInstance = GameObject.Find("BombPickup(Clone)"); if (bombInstance != null) { //Destroy all bomb pick ups that are "owned" by this parent instance DestroyMyBombs(gameObject); } //Spawn New Bombs CreateAllBombs(); //Apply Time Penalty GameTimerScript.ApplyTimePenalty(10.0f); } } else { //Hide Help Text bombExplainText.SetActive(false); } }
float actualTimer; //Hidden timer value that will be used to spawn relative to the global game time // Use this for initialization void Start() { timerObject = GameObject.FindGameObjectWithTag("Timer"); //Grab the object that contains the timer gameTimer = timerObject.GetComponent <GameTimerScript>(); actualTimer = gameTimer.timer + spawnTimer; }
//When the player leaves the trigger, apply the accumulated penalty time and reset it void OnTriggerExit(Collider other) { if (enableTimePenalty) { //Call Event to Apply Time Penalty GameTimerScript.ApplyTimePenalty(totalPenaltyTime); totalPenaltyTime = 0.0f; } }
// Use this for initialization void Start() { clickDetect = GetComponent <ClickDetectScript>(); // Grab the click detection attached to this object holdDetect = GetComponent <HoldDetectScript>(); // Grab the hold detection attached to this object dataObject = GameObject.FindGameObjectWithTag("Timer"); //Grab the object that contains the data gameCam = GameObject.FindGameObjectWithTag("UICam").GetComponent <Camera>(); playerData = dataObject.GetComponent <PlayerDataScript>(); //Grab player data gameTimer = dataObject.GetComponent <GameTimerScript>(); //Grab timer data timeSpawned = gameTimer.timer; //Sync object timer to game time feedbackAnimator = feedbackObject.GetComponent <Animator>(); // Grab the animator for the feedback object feedbackExploAnimator = feedbackExploObject.GetComponent <Animator>(); }
/// <summary> /// Takes the name and time of a high score and converts in to formmated string /// </summary> /// <param name="a_playerName"></param> /// <param name="a_time"></param> /// <returns>Formatted High Score String (NAME - 00:00:00)</returns> private string FormatHighScoreString(string a_playerName, float a_time) { //If time = 0 then it should not count as a high score if (a_time != 0) { string returnName = a_playerName.ToUpper(); string returnTime = GameTimerScript.FormatTimeString(a_time); return(returnName + " - " + returnTime + "\n"); } else { return(string.Empty); } }
//Update all UI Values void Start() { //Make Cursor Visible Cursor.lockState = CursorLockMode.None; Cursor.visible = true; //Show Total Time TotalTimeText.text = GameTimerScript.GetFormattedElapsedTime(); //Show Penalty Time PenaltyTimeText.text = "Of which " + GameTimerScript.GetFormattedPenaltyTime() + " was gained trough penalty time"; //Do High Score Saving if (HighScoreManager.SaveHighScore(GameTimerScript.elapsedTime)) { //If we succesfully saved a new high score inform the user HighScoreText.text = "NEW HIGHSCORE! (TOP 5)"; } else { //Else Leave it empty HighScoreText.text = string.Empty; } }
// Update is called once per frame void Update() { gameTimer = dataObject.GetComponent <GameTimerScript>(); // update timer clickDetect = GetComponent <ClickDetectScript>(); // Grab the click detection attached to this object playerData = dataObject.GetComponent <PlayerDataScript>(); //Grab player data scoreMultiplier = playerData.multiplier; if (clickDetect.wasClicked) //If it has been clicked { //This is where we do stuff after the object has been clicked playerData.successfulHits++; //Log successful hit in data /* JS Needs to instantiate HitFeedbackArt prefab at parent's transform and set animator's trigger "Bad", "Good" or "Perfect", or "Miss" * Tried to be smart and set trigger here while HitFeedbackArt was child to this object, of course it got destroyed :~( */ // Debug.Log("We clicked it reddit"); playerData.allSuccessfulHits++; playerData.setSuccessfulHits++; if (gameTimer.timer - realTimeSpawned >= baseTimeToPerfectLow && gameTimer.timer - realTimeSpawned <= baseTimeToPerfectHigh) { feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); audioObject.SetActive(true); feedbackAnimator.SetTrigger("Perfect"); feedbackExploAnimator.SetTrigger("Perfect"); playerData.playerCombo++; playerData.playerScore += (400 * scoreMultiplier); gameObject.SetActive(false); //Deactivate the target object } else if (gameTimer.timer - realTimeSpawned > baseTimeToGoodBeforeLow & gameTimer.timer - realTimeSpawned < baseTimeToPerfectLow || gameTimer.timer - realTimeSpawned > baseTimeToPerfectHigh && gameTimer.timer - realTimeSpawned < baseTimeToGoodAfterHigh) { feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); feedbackAnimator.SetTrigger("Good"); feedbackExploAnimator.SetTrigger("Good"); audioObject.SetActive(true); playerData.playerCombo++; playerData.playerScore += (200 * scoreMultiplier); gameObject.SetActive(false); //Deactivate the target object } else { feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); feedbackAnimator.SetTrigger("Bad"); feedbackExploAnimator.SetTrigger("Bad"); audioObject.SetActive(true); playerData.playerCombo = 0; playerData.playerScore += (50 * scoreMultiplier); gameObject.SetActive(false); //Deactivate the target object } //It's likely we need to pass some data to the feedbackObject before setting it to false, we'll want the feedbackObject to delete the parent when it's done being all flashy } if (gameTimer.timer > timeSpawned + timeToDie) //If the object has outlasted its live timer { //This should mostly be used to report a failed click/clean up unused objects playerData.unsuccessfulHits++; //Log failed hit in data /* JS Again needs to instantiate HitFeedbackArt with trigger "Miss" * */ //Debug.Log("Object should die here"); playerData.allUnsuccessfulHits++; playerData.setUnsuccessfulHits++; feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); feedbackAnimator.SetTrigger("Miss"); feedbackExploAnimator.SetTrigger("Miss"); playerData.playerCombo = 0; gameObject.SetActive(false); //Deactivate the target object } if (gameTimer.timer > timeSpawned + timeToClick) { //Shouldn't actually need this check, should be handled inside the "Was clicked" part, but hey! //Debug.Log("THIS WAS THE CLICK MOMENT"); } }
// Update is called once per frame void Update() { gameTimer = dataObject.GetComponent <GameTimerScript>(); // update timer clickDetect = GetComponent <ClickDetectScript>(); // Grab the click detection attached to this object holdDetect = GetComponent <HoldDetectScript>(); // Grab the hold detection attached to this object playerData = dataObject.GetComponent <PlayerDataScript>(); //Grab player data scoreMultiplier = playerData.multiplier; if (clickDetect.wasClicked && holdDetect.isHeld) //If it has been clicked and is being held down { wasHeld = true; //Logs that the object has been hit timeHeld += Time.deltaTime; if (startedPlaying) { holdAnim.speed = (1 / speedMod); audioObject.SetActive(true); } if (!startedPlaying) { holdAnim.SetBool("Held", true); startedPlaying = true; audioObject.SetActive(true); } } if (!clickDetect.wasClicked && wasHeld) //JS If it has been clicked and is released { holdAnim.speed = 0; //JS audioObject.SetActive(false); clickDetect.touchDetect = false; } /* * * if(wasHeld && !holdDetect.isHeld) // If the player held over, but released * { * //This should mostly be used to report a failed click/clean up unused objects * playerData.unsuccessfulHits++; //Log failed hit in data * * //Debug.Log("Object should die here"); * Destroy(theParent); * } */ if (gameTimer.timer > timeSpawned + timeToDie && timeHeld == 0f) //If the object has outlasted its live timer and it was never charged { //This should mostly be used to report a failed click/clean up unused objects playerData.unsuccessfulHits++; //Log failed hit in data playerData.allUnsuccessfulHits++; playerData.setUnsuccessfulHits++; //Debug.Log("Object should die here"); feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); feedbackExploAnimator.SetTrigger("Miss"); audioObject.SetActive(false); feedbackAnimator.SetTrigger("Miss"); playerData.playerCombo = 0; gameObject.SetActive(false); //Deactivate the target object } if (gameTimer.timer > timeSpawned + timeToDie && timeHeld > 0f && timeHeld <= baseTimeForGood) //If the object has outlasted its live but it got charged a bit { //This should mostly be used to report a failed click/clean up unused objects playerData.unsuccessfulHits++; //Log failed hit in data playerData.allUnsuccessfulHits++; playerData.setUnsuccessfulHits++; //Debug.Log("Object should die here"); feedbackObject.SetActive(true); //Activate the feedback object audioObject.SetActive(false); feedbackExploObject.SetActive(true); feedbackExploAnimator.SetTrigger("Bad"); feedbackAnimator.SetTrigger("Bad"); playerData.playerCombo = 0; playerData.playerScore += (50 * scoreMultiplier); gameObject.SetActive(false); //Deactivate the target object } if (gameTimer.timer > timeSpawned + timeToDie && timeHeld > baseTimeForGood) //If the object has outlasted its live but it got charged a lot { //This should mostly be used to report a failed click/clean up unused objects playerData.successfulHits++; //Log failed hit in data playerData.allSuccessfulHits++; playerData.setSuccessfulHits++; //Debug.Log("Object should die here"); feedbackObject.SetActive(true); //Activate the feedback object audioObject.SetActive(false); feedbackExploObject.SetActive(true); feedbackExploAnimator.SetTrigger("Good"); feedbackAnimator.SetTrigger("Good"); playerData.playerCombo++; playerData.playerScore += (200 * scoreMultiplier); gameObject.SetActive(false); //Deactivate the target object } if (timeHeld >= timeToHold) //If it has been held long enough { //This is where we do stuff after the object has been clicked playerData.successfulHits++; //Log successful hit in data // Debug.Log("We clicked it reddit"); playerData.allSuccessfulHits++; playerData.setSuccessfulHits++; feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); feedbackExploAnimator.SetTrigger("Perfect"); feedbackAnimator.SetTrigger("Perfect"); audioObject.SetActive(false); playerData.playerCombo++; playerData.playerScore += (400 * scoreMultiplier); gameObject.SetActive(false); //Deactivate the target object } if (gameTimer.timer > timeSpawned + timeToClick) { //Shouldn't actually need this check, should be handled inside the "Was clicked" part, but hey! //Debug.Log("THIS WAS THE CLICK MOMENT"); } }
// Update is called once per frame void Update() { gameTimer = dataObject.GetComponent <GameTimerScript>(); // update timer clickDetect = GetComponent <ClickDetectScript>(); // Grab the click detection attached to this object holdDetect = GetComponent <HoldDetectScript>(); // Grab the hold detection attached to this object playerData = dataObject.GetComponent <PlayerDataScript>(); //Grab player data scoreMultiplier = playerData.multiplier; if (clickDetect.wasClicked && holdDetect.isHeld) //If it has been clicked and is being held down { wasHeld = true; //Logs that the object has been hit } if (keepGoing) { SlideObject(); oncePerFrame = true; } if (wasHeld && !keepGoing) { if (!oncePerFrame) { audioObject.SetActive(true); SlideObject(); } } if (wasHeld && !holdDetect.isHeld && !keepGoing) // If the player held over, but released { //This should mostly be used to report a failed click/clean up unused objects playerData.unsuccessfulHits++; //Log failed hit in data playerData.allUnsuccessfulHits++; playerData.setUnsuccessfulHits++; playerData.playerCombo = 0; //Debug.Log("Object should die here"); feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); audioObject.SetActive(false); //Deactivate the button sound object feedbackObject.transform.eulerAngles = new Vector3(0, 0, -theParent.transform.rotation.z); feedbackExploObject.transform.eulerAngles = new Vector3(0, 0, -theParent.transform.rotation.z); feedbackAnimator.SetTrigger("Bad"); feedbackExploAnimator.SetTrigger("Bad"); sliderGraphicsParent.SetActive(false); //Deactivate the target object } if (holdDetect.isHeld && clickDetect.wasClicked) //If it has been clicked and is being held down { timeHeld += Time.deltaTime; } if (gameTimer.timer > timeSpawned + timeToDie) //If the object has outlasted its live timer { //This should mostly be used to report a failed click/clean up unused objects playerData.unsuccessfulHits++; //Log failed hit in data playerData.allUnsuccessfulHits++; playerData.setUnsuccessfulHits++; playerData.playerCombo = 0; //Debug.Log("Object should die here"); feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); audioObject.SetActive(false); //Deactivate the button sound object feedbackObject.transform.eulerAngles = new Vector3(0, 0, -theParent.transform.rotation.z); feedbackExploObject.transform.eulerAngles = new Vector3(0, 0, -theParent.transform.rotation.z); feedbackAnimator.SetTrigger("Bad"); feedbackExploAnimator.SetTrigger("Bad"); sliderGraphicsParent.SetActive(false); //Deactivate the target object } if (moveFinished) //If it has been held long enough { //This is where we do stuff after the object has been clicked playerData.successfulHits++; //Log successful hit in data // Debug.Log("We clicked it reddit"); playerData.allSuccessfulHits++; playerData.setSuccessfulHits++; playerData.playerCombo++; playerData.playerScore += (400 * scoreMultiplier); feedbackObject.SetActive(true); //Activate the feedback object feedbackExploObject.SetActive(true); audioObject.SetActive(false); //Deactivate the button sound object feedbackObject.transform.eulerAngles = new Vector3(0, 0, -theParent.transform.rotation.z); feedbackExploObject.transform.eulerAngles = new Vector3(0, 0, -theParent.transform.rotation.z); feedbackAnimator.SetTrigger("Perfect"); feedbackExploAnimator.SetTrigger("Perfect"); sliderGraphicsParent.SetActive(false); //Deactivate the target object } if (gameTimer.timer > timeSpawned + timeToClick) { //Shouldn't actually need this check, should be handled inside the "Was clicked" part, but hey! //Debug.Log("THIS WAS THE CLICK MOMENT"); } }