// Start is called before the first frame update void Start() { //Set starting background currentBackground = "darkForest"; // Music for the specific background BackgroundAudio.PlaySound("DarkForest"); // musicIsOff = false; }
// Start is called before the first frame update private void OnTriggerEnter2D(Collider2D other) { if (other.transform.tag == "Coin") { BackgroundAudio.PlaySound("Coin"); coin++; textCoins.text = coin.ToString(); Destroy(other.gameObject); } }
void OnTriggerEnter2D(Collider2D collider) { var p = collider.gameObject.GetComponent <PlayerController>(); if (p != null) { BackgroundAudio.PlaySound("Death"); var ev = Schedule <PlayerEnteredDeathZone>(); ev.deathzone = this; } }
// Update is called once per frame void Update() { // Initial background music if (musicIsOff) { //BackgroundAudio.PlaySound("MainTheme"); //musicIsOff = false; } //Change backgrounds according to coin number GameObject thePlayer = GameObject.Find("Player"); CoinCollision coinScript = thePlayer.GetComponent <CoinCollision>(); int coinNum = (int)coinScript.coin; //Get number of coins from the coin script //Check number of coins if (coinNum == 10) { //Change to rockyHills if (currentBackground != "rockyHills") { currentBackground = "rockyHills"; //Animate //out with current background FadeOut = darkForest.GetComponent <Animator>(); FadeOut.SetTrigger("FadeOut"); //in with new background FadeIn = rockyHills.GetComponent <Animator>(); FadeIn.SetTrigger("FadeIn"); //Reset all backgrounds away /* * darkForest.transform.position = new Vector3(darkForest.transform.position.x, -100, darkForest.transform.position.z); * peacefulMountains.transform.position = new Vector3(peacefulMountains.transform.position.x, -100, peacefulMountains.transform.position.z); * rockyHills.transform.position = new Vector3(rockyHills.transform.position.x, -100, rockyHills.transform.position.z); * waterfalls.transform.position = new Vector3(waterfalls.transform.position.x, -100, waterfalls.transform.position.z); */ //Move the one we want rockyHills.transform.position = new Vector3(rockyHills.transform.position.x, -1, rockyHills.transform.position.z); // Music for the specific background BackgroundAudio.PlaySound("RockyHills"); //Change dialogue GameObject D = GameObject.Find("DialogueManager"); Dialog dialogScript = D.GetComponent <Dialog>(); StartCoroutine(DialogCoroutine()); } } else if (coinNum == 20) { //Change to peacefulMountains if (currentBackground != "peacefulMountains") { //Animate //out with current background FadeOut = rockyHills.GetComponent <Animator>(); FadeOut.SetTrigger("FadeOut"); //in with new background FadeIn = peacefulMountains.GetComponent <Animator>(); FadeIn.SetTrigger("FadeIn"); currentBackground = "peacefulMountains"; //Reset all backgrounds away /* * darkForest.transform.position = new Vector3(darkForest.transform.position.x, -100, darkForest.transform.position.z); * peacefulMountains.transform.position = new Vector3(peacefulMountains.transform.position.x, -100, peacefulMountains.transform.position.z); * rockyHills.transform.position = new Vector3(rockyHills.transform.position.x, -100, rockyHills.transform.position.z); * waterfalls.transform.position = new Vector3(waterfalls.transform.position.x, -100, waterfalls.transform.position.z); */ //load new FadeIn = peacefulMountains.GetComponent <Animator>(); FadeIn.SetTrigger("FadeIn"); //Move the one we want peacefulMountains.transform.position = new Vector3(peacefulMountains.transform.position.x, -1, peacefulMountains.transform.position.z); // Music for the specific background BackgroundAudio.PlaySound("PeacefulMountains"); //Change dialogue GameObject D = GameObject.Find("DialogueManager"); Dialog dialogScript = D.GetComponent <Dialog>(); StartCoroutine(DialogCoroutine()); } } else if (coinNum == 35) { //Change to waterfalls if (currentBackground != "waterfalls") { //Animate //out with current background FadeOut = peacefulMountains.GetComponent <Animator>(); FadeOut.SetTrigger("FadeOut"); //in with new background FadeIn = waterfalls.GetComponent <Animator>(); FadeIn.SetTrigger("FadeIn"); currentBackground = "waterfalls"; //Reset all backgrounds away /* * darkForest.transform.position = new Vector3(darkForest.transform.position.x, -100, darkForest.transform.position.z); * peacefulMountains.transform.position = new Vector3(peacefulMountains.transform.position.x, -100, peacefulMountains.transform.position.z); * rockyHills.transform.position = new Vector3(rockyHills.transform.position.x, -100, rockyHills.transform.position.z); * waterfalls.transform.position = new Vector3(waterfalls.transform.position.x, -100, waterfalls.transform.position.z); */ //Move the one we want waterfalls.transform.position = new Vector3(waterfalls.transform.position.x, -1, waterfalls.transform.position.z); // Music for the specific background BackgroundAudio.PlaySound("Waterfalls"); //Change dialogue GameObject D = GameObject.Find("DialogueManager"); Dialog dialogScript = D.GetComponent <Dialog>(); dialogScript.NextSentence(); } } }
protected override void Update() { // Initial background music if (musicIsOff) { BackgroundAudio.PlaySound("MainTheme"); musicIsOff = false; } if (controlEnabled) { //move.x = Input.GetAxis("Horizontal"); //this was the previous arrow key input move.x = playerSpeed; //set player speed //As long as the speed is under max, increase slowly if (playerSpeed > maxSpeed) { playerSpeed -= decreaseSpeed; } /* * if (coinNum == 1) * { * //Reset all backgrounds away * background1.transform.position = new Vector3(background1.transform.position.x, -100, background1.transform.position.z); * background2.transform.position = new Vector3(background2.transform.position.x, -100, background2.transform.position.z); * background3.transform.position = new Vector3(background3.transform.position.x, -100, background3.transform.position.z); * background4.transform.position = new Vector3(background4.transform.position.x, -100, background4.transform.position.z); * * //Move the one we want * background1.transform.position = new Vector3(background1.transform.position.x, 0, background1.transform.position.z); * * // Music for the specific background * BackgroundAudio.PlaySound("DarkForest"); * } * if (Input.GetKey("1")) * { * //Reset all backgrounds away * background1.transform.position = new Vector3(background1.transform.position.x, -100, background1.transform.position.z); * background2.transform.position = new Vector3(background2.transform.position.x, -100, background2.transform.position.z); * background3.transform.position = new Vector3(background3.transform.position.x, -100, background3.transform.position.z); * background4.transform.position = new Vector3(background4.transform.position.x, -100, background4.transform.position.z); * * //Move the one we want * background1.transform.position = new Vector3(background1.transform.position.x, 0, background1.transform.position.z); * * // Music for the specific background * BackgroundAudio.PlaySound("DarkForest"); * } * if (Input.GetKey("2")) * { * //Reset all backgrounds away * background1.transform.position = new Vector3(background1.transform.position.x, -100, background1.transform.position.z); * background2.transform.position = new Vector3(background2.transform.position.x, -100, background2.transform.position.z); * background3.transform.position = new Vector3(background3.transform.position.x, -100, background3.transform.position.z); * background4.transform.position = new Vector3(background4.transform.position.x, -100, background4.transform.position.z); * * //Move the one we want * background2.transform.position = new Vector3(background2.transform.position.x, 0, background2.transform.position.z); * * // Music for the specific background * BackgroundAudio.PlaySound("RockyHills"); * } * if (Input.GetKey("3")) * { * //Reset all backgrounds away * background1.transform.position = new Vector3(background1.transform.position.x, -100, background1.transform.position.z); * background2.transform.position = new Vector3(background2.transform.position.x, -100, background2.transform.position.z); * background3.transform.position = new Vector3(background3.transform.position.x, -100, background3.transform.position.z); * background4.transform.position = new Vector3(background4.transform.position.x, -100, background4.transform.position.z); * * //Move the one we want * background3.transform.position = new Vector3(background3.transform.position.x, 0, background3.transform.position.z); * * // Music for the specific background * BackgroundAudio.PlaySound("PeacefulMountains"); * } * if (Input.GetKey("4")) * { * //Reset all backgrounds away * background1.transform.position = new Vector3(background1.transform.position.x, -100, background1.transform.position.z); * background2.transform.position = new Vector3(background2.transform.position.x, -100, background2.transform.position.z); * background3.transform.position = new Vector3(background3.transform.position.x, -100, background3.transform.position.z); * background4.transform.position = new Vector3(background4.transform.position.x, -100, background4.transform.position.z); * * //Move the one we want * background4.transform.position = new Vector3(background4.transform.position.x, 0, background4.transform.position.z); * * // Music for the specific background * BackgroundAudio.PlaySound("Waterfalls"); * } */ if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump")) { jumpState = JumpState.PrepareToJump; } else if (Input.GetButtonUp("Jump")) { stopJump = true; Schedule <PlayerStopJump>().player = this; } } else { move.x = 0; } UpdateJumpState(); base.Update(); }