void Start() { // Find HealthScript from the "Diamonds/Hitpoints" GameObject. If not found, return null. try { HS = GameObject.Find("Diamonds/Hitpoints").GetComponent <HealthScript>(); } catch { // Debug.Log("HealthScript not found."); HS = null; } // Find HazardScript from a GameObject tagged "Hazard". If not found, return null. try { HazS = GameObject.FindWithTag("Hazard").GetComponent <HazardScript>(); } catch { //Debug.Log("HazardScript not found."); HazS = null; } //References RigidBody2D to variable rb rb = GetComponent <Rigidbody2D>(); //Sets extraJumpCountReset to the value of extraJumpCount so it can later be reset back to the original value. extraJumpCountReset = extraJumpCount; //Gets the object's sprite renderer and sets it to sr. sr = transform.GetComponent <SpriteRenderer>(); r = sr.color.r; g = sr.color.g; b = sr.color.b; alpha = sr.color.a; }
void Awake() { audio = GetComponent <AudioSource>(); GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); for (int i = 0; i < players.Length; i++) { { if (players[i].GetComponent <player1Controler>().PlayerNumber == 1) { PlayersList[0] = players[i]; Player1Pos = PlayersList[0].transform.position; } else if (players[i].GetComponent <player1Controler>().PlayerNumber == 2) { PlayersList[1] = players[i]; Player2Pos = PlayersList[1].transform.position; } } } m_Particle = GameObject.FindGameObjectWithTag("EnvironmentParticle").GetComponent <EnvironmentParticle>(); m_Hazard = GameObject.FindGameObjectWithTag("EnvironmentHazard").GetComponent <HazardScript>(); }
//Run when the player collides with this trigger void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.tag == "Player" && Time.time >= timeCanRetriggerEnter && this.gameObject.tag == "Enemy" && this.gameObject.GetComponent <AIControllerPatrolPig>().m_canSeePlayer) { //Get HealthController and set isDead flag HealthController healthController = targetObject.GetComponent <HealthController>(); //If the HealthController exists if (healthController != null) { //Set isDead flage healthController.isDead = true; } else //Debug.Log("Health Controller is missing on target"); //If trigger once, disable collision - moved from inside Enable section to allow a one-time trigger for all types of triggers if (triggerOnce) { this.collider2D.enabled = false; } } //If player continue else if ((collider.gameObject.tag == "Player") && this.gameObject.tag != "Enemy" && Time.time >= timeCanRetriggerEnter) { //If type Kill if (triggerType == TriggerType.Kill) { //Get HealthController and set isDead flag HealthController healthController = targetObject.GetComponent <HealthController>(); //If the HealthController exists if (healthController != null) { //Set isDead flage healthController.isDead = true; } else //Debug.Log("Health Controller is missing on target"); //If trigger once, disable collision - moved from inside Enable section to allow a one-time trigger for all types of triggers if (triggerOnce) { this.collider2D.enabled = false; } } //If type Destroy else if (triggerType == TriggerType.Destroy) { //If the timer is not set to infinite (0) if (destroyTimer < 0) { destroyTimer = 0; } //Set the this object to be destroyed Destroy(targetObject, destroyTimer); //If trigger once, disable collision - moved from inside Enable section to allow a one-time trigger for all types of triggers if (triggerOnce) { this.collider2D.enabled = false; } } //If this is an Enable trigger, find the type of controller and enable it! else if (triggerType == TriggerType.Enable) { AIController AIController = targetObject.GetComponent <AIController>(); if (AIController != null) { AIController.startEnabled = true; if (anim != null) { anim.SetTrigger("trigger"); } } AIControllerPatrolPig AIControllerPatrolPig = targetObject.GetComponent <AIControllerPatrolPig>(); if (AIControllerPatrolPig != null) { AIControllerPatrolPig.m_isStartEnabled = true; if (anim != null) { anim.SetTrigger("trigger"); } } MovingPlatformLinear movingController = targetObject.GetComponent <MovingPlatformLinear>(); if (movingController != null) { movingController.startEnabled = true; if (anim != null) { anim.SetTrigger("trigger"); } } OneWayPlatforms oneWayController = targetObject.GetComponent <OneWayPlatforms>(); if (oneWayController != null) { oneWayController.startEnabled = true; if (anim != null) { anim.SetTrigger("trigger"); } } HazardScript hazardController = targetObject.GetComponent <HazardScript>(); if (hazardController != null) { hazardController.startEnabled = true; if (anim != null) { anim.SetTrigger("trigger"); } } Destructible_Object destructibleController = targetObject.GetComponent <Destructible_Object>(); if (destructibleController != null) { destructibleController.startEnabled = true; if (anim != null) { anim.SetTrigger("trigger"); } } InvisibleObject invisibleController = targetObject.GetComponent <InvisibleObject>(); if (invisibleController != null) { //Reverse the visability of the invisible object invisibleController.startEnabled = !invisibleController.startEnabled; if (anim != null) { anim.SetTrigger("trigger"); } } //If trigger once, disable collision - moved from inside Enable section to allow a one-time trigger for all types of triggers if (triggerOnce) { this.collider2D.enabled = false; } } else if (triggerType == TriggerType.Sound) //If this is a sound trigger, then the sound will play - moved from inside Enable section to fix bug { Play(soundToPlay); //If trigger once, disable collision - moved from inside Enable section to allow a one-time trigger for all types of triggers if (triggerOnce) { this.collider2D.enabled = false; } } else if (triggerType == TriggerType.ProximityTrigger) //If this is an ProximityTrigger, find the type of AI throw the appropriate flag { AIController AIController = targetObject.GetComponent <AIController>(); if (AIController != null) { AIController.playerIsNear = true; } } //Reset retrigger time timeCanRetriggerEnter = Time.time + 1.0f; } }
void OnTriggerEnter2D(Collider2D whatIHit) { this.GetComponent <BoxCollider2D>().isTrigger = false; switch (whatIHit.transform.tag) { case "Ladder": canClimb = true; canClimbUp = true; //Debug.Log("Ladder"); break; case "Antidote": string antidoteType; AntidoteScript antidoteScript = whatIHit.gameObject.GetComponent <AntidoteScript>(); antidoteType = antidoteScript.antidoteType; ChangeAntidote(antidoteType); Destroy(whatIHit.gameObject); break; case "Hazard": string hazardType; HazardScript hazardScript = whatIHit.gameObject.GetComponent <HazardScript>(); hazardType = hazardScript.hazardType; switch (hazardType) { case "Snake": if (!immuneSnake) { print("Player Killed By " + hazardType); gameManager.RestartGame(); } break; case "Vine": if (!immuneVine) { print("Player Killed By " + hazardType); gameManager.RestartGame(); } break; case "Smoke": if (!immuneSmoke) { print("Player Killed By " + hazardType); gameManager.RestartGame(); } break; } break; case "Portal": gameManager.GameWon(); break; case "LadderTop": canClimb = true; canClimbUp = false; break; case "OneWayPlatform": canDropDown = true; break; } /*if (whatIHit.transform.tag == "Ladder") * { * canClimb = true; * } * if (whatIHit.transform.tag == "Antidote") * { * string antidoteType; * AntidoteScript antidoteScript = whatIHit.gameObject.GetComponent<AntidoteScript>(); * antidoteType = antidoteScript.antidoteType; * switch (antidoteType) * { * case "Snake": * immuneSnake = true; * break; * case "Vine": * immuneVine = true; * break; * } * * Destroy(whatIHit.gameObject); * } * if (whatIHit.transform.tag == "Snake") * { * if (immuneSnake) * { * * } * else * { * Debug.Log("dead"); * } * }*/ }