// Use this for initialization void Start() { timeLeft = 999; kunaiCount = GameObject.Find("Game Controller").GetComponent <GameController>().kunaiCount; animator = GetComponent <Animator>(); weaponChargeAnimator = GameObject.Find("Weapon Charge Bar").GetComponent <Animator>(); attackLimiter = true; throwingLimiter = true; moveRight = true; canMove = true; inTheAir = false; isSliding = false; canSlide = true; isAlive = true; airJump = true; isInvulnerable = false; notStunned = true; isCrouching = false; gameIsOver = false; onSolidGround = true; gameOver.gameObject.SetActive(false); gameOverBackground.gameObject.SetActive(false); gamePaused.gameObject.SetActive(false); if (GameObject.Find("Game Controller").GetComponent <GameController>().keepPowerup == true) { GameObject.Find("Game Controller").GetComponent <GameController>().keepPowerup = false; } else { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); } speed = 0.2f; fastSpeed = 0.5f; myRigidBody = GetComponent <Rigidbody2D>(); boxCollider2D = GetComponent <BoxCollider2D>(); ninjaHealth = GetComponent <NinjaHealth>(); ninjaHealth.SetHealth(health); weaponCharge = GameObject.Find("Weapon Charge").GetComponent <Slider>(); weaponCharge.value = 0f; scoreText.text = score.ToString(); scoreTextShadow.text = score.ToString(); StartCoroutine(TickingTime()); if (GameObject.Find("Game Controller").GetComponent <GameController>().nextLevel == 1) { GameObject.Find("Music Manager").GetComponent <MusicManagerInstance>().PlayTrack("Level 1 revised"); } else { GameObject.Find("Music Manager").GetComponent <MusicManagerInstance>().PlayTrack("Level 2"); } }
void OnTriggerEnter2D(Collider2D collider) { if (collider.tag == "Ground" || collider.tag == "Solid Ground") { if (animator.GetBool("isRunning") == false && isSliding == false && isAlive == true) { Debug.Log("Player is on the ground."); inTheAir = false; airJump = false; animator.Play("Idle"); } } if (collider.tag == "Enemy Attack" && isInvulnerable == false && isAlive == true) { Debug.Log("Collision"); StartCoroutine(isInjured()); StartCoroutine(StunPlayer(0.4f)); if (collider.gameObject.GetComponent <EnemyDamage>() != null) { health -= collider.gameObject.GetComponent <EnemyDamage>().damage; int r = Random.Range(0, 2); if (r == 0) { injuredSound1.Play(); } else if (r == 1) { injuredSound2.Play(); } } else { Debug.LogError("Enemy damage not found."); } ninjaHealth.SetHealth(health); if (health <= 0) { PlayerDead(); StartCoroutine(GameOverFool()); } } if (collider.tag == "Bonus") { if (collider.gameObject.GetComponent <Coin>() != null) { score += collider.gameObject.GetComponent <Coin>().value *pendantBonus(); UpdateScoreText(); } } if (collider.tag == "Solid Ground") { onSolidGround = true; GetComponent <BoxCollider2D>().isTrigger = false; } if (collider.tag == "Ground") { onSolidGround = false; } if (collider.tag == "Item") { if (collider.gameObject.GetComponent <Key>() != null) { if (collider.gameObject.GetComponent <Key>().keyType == Key.collectKey.bronze) { GameObject.Find("Game Controller").GetComponent <GameController>().bronzeKeys++; bronzeKeyText.text = GameObject.Find("Game Controller").GetComponent <GameController>().bronzeKeys.ToString(); } if (collider.gameObject.GetComponent <Key>().keyType == Key.collectKey.silver) { GameObject.Find("Game Controller").GetComponent <GameController>().silverKeys++; silverKeyText.text = GameObject.Find("Game Controller").GetComponent <GameController>().silverKeys.ToString(); } if (collider.gameObject.GetComponent <Key>().keyType == Key.collectKey.gold) { GameObject.Find("Game Controller").GetComponent <GameController>().goldKeys++; goldKeyText.text = GameObject.Find("Game Controller").GetComponent <GameController>().goldKeys.ToString(); } } } if (collider.tag == "Powerup") { GameObject.Find("Game Controller").GetComponent <GameController>().keepPowerup = true; if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.shield) { // Set shield to true and all others false GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Shield Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.shield; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.bluePendant) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Blue Crystal Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.bluePendant; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.redPendant) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Red Crystal Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.redPendant; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.hammer) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Hammer Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.hammer; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.bluePotion) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Blue Potion Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.bluePotion; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.redPotion) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Red Potion Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.redPotion; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.scroll) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Scroll Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.scroll; } if (collider.gameObject.GetComponent <Powerup>().powerupType == Powerup.collectPowerup.pot) { GameObject.Find("Game Controller").GetComponent <GameController>().ResetPowerups(); GameObject.Find("Pot Powerup").GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); powerupType = collectPowerup.pot; } } if (collider.tag == "Extra Kunai") { kunaiCount += 20; UpdateKunaiText(); } }