//When a collision has taken place and the object contains the desired tag, //player score is incrimented and the object is marked as expired private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == objectString && recievedBag == false) { if ((FindActiveChild(collision.gameObject).tag == desiredModel) && (FindActiveChild(collision.gameObject).GetComponentInChildren <Renderer>().material.color == desiredCol) && (FindActiveChild(collision.gameObject).GetComponentInChildren <Renderer>().material.GetTexture("_MainTex") == desiredTex)) { if (collision.gameObject.GetComponent <ObjectInteractCursorScript>().hasExpired != true) { gameController.IncrimentPlayerScore(10); gameController.GetComponent <AudioManager>().PlaySound("General_Positive_Beep_01"); collision.gameObject.GetComponent <ObjectInteractCursorScript>().hasExpired = true; //Set mood to Happy moodScript.SetState(1); } } else { gameController.IncrimentPlayerScore(-5); gameController.GetComponent <AudioManager>().PlaySound("General_Negative_Beep_01"); collision.gameObject.GetComponent <ObjectInteractCursorScript>().hasExpired = true; //Set mood to Angry moodScript.SetState(2); } recievedBag = true; } else if (collision.gameObject.tag == "ResetBarrier") { Reinitialise(); } }
//Upon entering the collision space of a collider marked trigger via inspector //Used for gate collisions void OnTriggerEnter(Collider col) { //Game stage variable to track wether first or second set of turnstiles are in play int gameStage = GameObject.FindGameObjectWithTag("PassengerManager").GetComponent <PlayerMovementImmigration>().gameStage; //Gets the numerical value of the second last character in the string of a game objects name //Intended for use with the Turnstiles as their naming scheme ends with a number in (n) format thus the second last character is acquired int colliderNum = (int)char.GetNumericValue(col.gameObject.transform.parent.name.ToCharArray()[col.gameObject.transform.parent.name.ToCharArray().Length - 2]); //Only evaluates the collided object should it belong to the current game stage //game stage 1 numbers 0->3, game stage 2 numbers 4->7 if ((gameStage == 0 && (colliderNum < 4)) || (gameStage == 1 && (colliderNum > 3))) { //If the colour of the gate matches with the colour of the passenger, reward points,set mood state to happy and play a positive sound effect //If the colour of the gate does not match, decrement points,set mood state to angry and play a negative sound effect if (col.tag == "Red") { if (gameObject.tag == "Red") { gameController.IncrimentPlayerScore(10); gameController.GetComponent <AudioManager>().PlaySound("General_Positive_Beep_01"); moodScript.SetState(1); } if (gameObject.tag == "Blue") { gameController.IncrimentPlayerScore(-5); gameController.GetComponent <AudioManager>().PlaySound("General_Negative_Beep_01"); moodScript.SetState(2); } } else if (col.tag == "Blue") { if (gameObject.tag == "Red") { //score.playerScore -= 5; gameController.IncrimentPlayerScore(-5); gameController.GetComponent <AudioManager>().PlaySound("General_Negative_Beep_01"); moodScript.SetState(2); } if (gameObject.tag == "Blue") { //score.playerScore += 10; gameController.IncrimentPlayerScore(10); gameController.GetComponent <AudioManager>().PlaySound("General_Positive_Beep_01"); moodScript.SetState(1); } } } }