IEnumerator DamageTimer() { yield return(new WaitForSeconds(delay)); // Enable pillar object pillar.SetActive(true); while (renderer.material.color.a > fadeAmount) { renderer.material.color -= new Color(0, 0, 0, fadeAmount); pillarRenderer.material.color -= new Color(0, 0, 0, fadeAmount); innerPillarRenderer.material.color -= new Color(0, 0, 0, fadeAmount); yield return(new WaitForSeconds(fadeAmount)); pillar.GetComponent <CapsuleCollider>().enabled = false; innerPillar.GetComponent <CapsuleCollider>().enabled = false; } if (finalPillarInAttack == true) { // Reset Castella's state CastellaController castella = GameObject.FindWithTag("Castella").GetComponent <CastellaController>(); castella.StartCoroutine("AttackTimer"); Debug.Log("Set attack timer on final pillar"); } Destroy(gameObject); }
void Start() { player = GameObject.FindWithTag("Player"); castella = GameObject.FindWithTag("Castella"); castellaC = castella.GetComponent <CastellaController>(); target = player; targetPosition = target.transform; speed = 12.5f; speedIncrement = 1.5f; hits = 1; rb = GetComponent <Rigidbody>(); player.GetComponent <AudioSource>().pitch = 0.5f + (0.1f * hits); player.GetComponent <AudioSource>().PlayOneShot(sfxProjectile, 1f); }
private void OnTriggerEnter(Collider other) { if (other.tag == "Key") { // Equip the item and destroy it when colliding with it if (equippedItem == 0) { Destroy(other.gameObject); equippedItem = 1; } else if (equippedItem == 2 && (Time.time - lastSwitchedItem) > 1) { Destroy(other.gameObject); Instantiate(Resources.Load("Umbrella"), other.transform.position, Quaternion.identity); lastSwitchedItem = Time.time; equippedItem = 1; Destroy(other.gameObject); } else if (equippedItem == 3 && (Time.time - lastSwitchedItem) > 1) { Destroy(other.gameObject); Instantiate(Resources.Load("Bubblewand"), other.transform.position, Quaternion.identity); lastSwitchedItem = Time.time; equippedItem = 1; Destroy(other.gameObject); } audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxBean, 1f); } if (other.tag == "Umbrella") { if (equippedItem == 0) { Destroy(other.gameObject); equippedItem = 2; } else if (equippedItem == 1 && (Time.time - lastSwitchedItem) > 1.0f) { Instantiate(Resources.Load("Key"), other.transform.position, Quaternion.identity); lastSwitchedItem = Time.time; equippedItem = 2; Destroy(other.gameObject); } else if (equippedItem == 3 && (Time.time - lastSwitchedItem) > 1) { Destroy(other.gameObject); Instantiate(Resources.Load("Bubblewand"), other.transform.position, Quaternion.identity); lastSwitchedItem = Time.time; equippedItem = 2; Destroy(other.gameObject); } audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxBean, 1f); } if (other.tag == "Bubblewand") { if (equippedItem == 0) { Destroy(other.gameObject); equippedItem = 3; } else if (equippedItem == 1 && (Time.time - lastSwitchedItem) > 1.0f) { Instantiate(Resources.Load("Key"), other.transform.position, Quaternion.identity); lastSwitchedItem = Time.time; equippedItem = 3; Destroy(other.gameObject); } else if (equippedItem == 2 && (Time.time - lastSwitchedItem) > 1) { Destroy(other.gameObject); Instantiate(Resources.Load("Umbrella"), other.transform.position, Quaternion.identity); lastSwitchedItem = Time.time; equippedItem = 3; Destroy(other.gameObject); } audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxBean, 1f); } if (other.tag == "Healthup") { // Heal and destroy item when colliding with it if (health < (2 + healthBonus)) { Destroy(other.gameObject); health = 2 + healthBonus; audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxHeal, 0.3f); } } if (other.tag == "Bean") { // Increment bean counter and destroy item when colliding with it HudBeans hudBeans = beanCount.GetComponent <HudBeans>(); Destroy(other.gameObject); beans++; //beans = 50; if (beans == hudBeans.beansTotal) { GameObject Beanstalk = GameObject.Find("Beanstalk"); Animator BeanstalkAnim = Beanstalk.GetComponent <Animator> (); GameObject Camera = GameObject.Find("Main Camera"); Camera.GetComponent <CameraSmoothFollow> ().setInstantFocus(Beanstalk.transform, new Vector3(0, -6, 14)); BeanstalkAnim.SetTrigger("Rise"); } audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxBean, 1f); if (beanFade != null) { StopCoroutine(beanFade); } beanFade = StartCoroutine(hudBeans.VisibilityTimer()); } if (other.tag == "Bean50") { HudBeans hudBeans = beanCount.GetComponent <HudBeans>(); beans = hudBeans.beansTotal; Destroy(other.gameObject); GameObject Beanstalk = GameObject.Find("Beanstalk"); Animator BeanstalkAnim = Beanstalk.GetComponent <Animator> (); GameObject Camera = GameObject.Find("Main Camera"); Camera.GetComponent <CameraSmoothFollow> ().setInstantFocus(Beanstalk.transform, new Vector3(0, -6, 14)); BeanstalkAnim.SetTrigger("Rise"); audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxBean, 1f); if (beanFade != null) { StopCoroutine(beanFade); } beanFade = StartCoroutine(hudBeans.VisibilityTimer()); } if (other.tag == "HealthBonus") { // Increase maximum health by 1 and destroy item when colliding with it Destroy(other.gameObject); HealthBonusController healthBonusController = other.GetComponent <HealthBonusController>(); if (healthBonusController.alreadyObtained == false) { healthBonus++; HealthBonusController.obtainedBonuses[healthBonusController.stageIndex] = true; } health = 2 + healthBonus; audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxHeal, 0.3f); StartCoroutine("ReturnTimer"); } if (other.tag == "Tutorial") { // Change tutorial text to collider's string tutorialText.GetComponent <Text>().text = other.gameObject.GetComponent <TutorialTextController>().tutorialString; if (hideTutorialText != null) { StopCoroutine(hideTutorialText); } showTutorialText = StartCoroutine(tutorialText.GetComponent <HudTutorial>().ShowTimer()); } if (other.tag == "Kill Zone") { // Restart the scene when colliding with a kill zone if (inBonus) { transform.position = retryPosition; Vector3 cameraCoordinates = retryPosition; CameraSmoothFollow cam = Camera.main.GetComponent <CameraSmoothFollow>(); cameraCoordinates.x -= cam.offset.x; cameraCoordinates.y -= cam.offset.y; cameraCoordinates.z -= cam.offset.z; Camera.main.transform.position = cameraCoordinates; //Debug.Log(Camera.main.transform.position); GameObject smoke = (GameObject)Instantiate(Resources.Load("Smoke")); smoke.transform.position = transform.position; smoke.transform.localScale = new Vector3(2f, 2f, 2f); health = 2 + healthBonus; } else { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } } if (other.tag == "Cactus") { if (invulnerable == false && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumCry")) { TakeDamage(); } } if (other.tag == "Firespot" && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumCry")) { if (invulnerable == false) { TakeDamage(); } } if (other.tag == "Castella Projectile") { if (invulnerable == false && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumKey") && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumCry")) { TakeDamage(); CastellaProjectileController castellaProjectile = other.gameObject.GetComponent <CastellaProjectileController>(); castellaProjectile.castellaC.projectileVolleys = 2 * (5 - castellaProjectile.castellaC.health); castellaProjectile.MakeSmoke(); Destroy(other.gameObject); CastellaController castella = GameObject.FindWithTag("Castella").GetComponent <CastellaController>(); castella.StartCoroutine("AttackTimer"); Debug.Log("Set attack timer on player hurt"); } } if (other.tag == "Castella Pillar" && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumCry")) { if (invulnerable == false) { TakeDamage(); } } if (other.tag == "Tornado") { if (moveDirection.y > 2f) { moveDirection.y = 2f; } audioSource.pitch = (Random.Range(0.9f, 1.1f)); audioSource.PlayOneShot(sfxTornado, 1f); } if (other.tag == "Lightning") { if (invulnerable == false && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumBlock") && !animator.GetCurrentAnimatorStateInfo(0).IsName("PlumCry")) { // Deal damage to player if not invulnerable and not spinning, then make the player invulnerable for a short time TakeDamage(); } } if (other.tag == "Bubble") { if (controller.isGrounded) { transform.Translate(0f, .1f, 0f); moveDirection.y = jumpForce; } else { moveDirection.y = jumpForce; Destroy(other.gameObject); } } if (other.tag == "Gem") { other.gameObject.GetComponent <GemController>().bossDoor.gems++; Destroy(other.gameObject); } }