Exemplo n.º 1
0
    public void ButtonClick(string buttonName)
    {
        //GetComponent<AudioSource>().clip = buttonAudio;
        //GetComponent<AudioSource>().Play();
        playHand = GameObject.FindGameObjectWithTag("PlayHand");
        //sg = playHand.GetComponent<StartGame> ();
        if (buttonName == "GunsButton")
        {
            HunterMovement hm = GameObject.FindGameObjectWithTag("Player").GetComponent <HunterMovement>();
            hm.stopStart();
            sr.reset(PlayerPrefs.GetInt("gunIndex") - 1);
            PlayerPrefs.SetInt("isGuncanvasOpen", 1);
            isGuncanvasOpen = true;
            guns.SetActive(true);
        }
        else if (buttonName == "BackButton")
        {
            PlayerPrefs.SetInt("isGuncanvasOpen", 0);
            isGuncanvasOpen = false;
            guns.SetActive(false);
            //sg.deactiveCanvas();
        }
        if (buttonName == "StartButton")
        {
            /**/
            GameObject.FindGameObjectWithTag("GameTitle").GetComponent <Animator>().SetBool("isDown", true);
            GameObject.FindGameObjectWithTag("ButtonCountDown").GetComponent <Animator>().SetBool("isStart", true);
            GameObject.FindGameObjectWithTag("CoinObject").GetComponent <Animator>().SetBool("isStart", true);
            PlayerPrefs.SetInt("isGuncanvasOpen", 0);
            StartCoroutine(startanimation());
        }

        if (buttonName == "MapButton")
        {
            HunterMovement hm = GameObject.FindGameObjectWithTag("Player").GetComponent <HunterMovement>();
            hm.stopStart();
            MapScrollScript sr = GameObject.FindGameObjectWithTag("GameController").GetComponent <MapScrollScript>();
            sr.reset(0);
            maps.SetActive(true);
        }

        if (buttonName == "BackMapButton")
        {
            maps.SetActive(false);
            //sg.deactiveCanvas();
        }

        if (buttonName == "Play")
        {
        }

        if (buttonName == "Pause")
        {
            Time.timeScale = 0;
            pauseCanvas.SetActive(true);
            pauseSmallCanvas.SetActive(false);
        }

        if (buttonName == "Resume")
        {
            Time.timeScale = 1;
            pauseCanvas.SetActive(false);
            pauseSmallCanvas.SetActive(true);
        }

        if (buttonName == "GiftButton")
        {
            gameover = GameObject.FindGameObjectWithTag("GameOver");
            gtemp    = (GameObject)Instantiate(gift, new Vector2(gift.transform.position.x, gift.transform.position.y), Quaternion.identity);
            gtemp.SetActive(true);


            Text giftText = GameObject.FindGameObjectWithTag("GiftCoin").GetComponent <Text> ();

            val           = Random.Range(50, 100);
            giftText.text = val.ToString();

            timerIcon         = GameObject.FindGameObjectWithTag("GreenStripeTimer").GetComponent <Image> ();
            timerIcon.enabled = false;

            minute = GameObject.FindGameObjectWithTag("GreenStripeMinute").GetComponent <Text> ();

            Text textObject = GameObject.FindGameObjectWithTag("FreeGiftText").GetComponent <Text> ();
            textObject.text = "FREE GIFT IN";

            /*Image label = GameObject.FindGameObjectWithTag ("FreeGiftIn_Label").GetComponent<Image> ();
             * label.enabled = true;*/

            timerIcon.enabled = true;
            minute.text       = "6:00";

            GameObject     gcc = GameObject.FindGameObjectWithTag("GameController");
            GameController gc  = gcc.GetComponent <GameController>();
            gc.resetGiftTimer();
            timeLeft = TotalTime;
            int sc = PlayerPrefs.GetInt("Score");
            sc = sc + val;
            PlayerPrefs.SetInt("Score", sc);

            GameObject giftButton = GameObject.FindGameObjectWithTag("GreenStripeButton");
            giftButton.SetActive(false);
            //GameOverVisibility(false);

            GameOverScript go_script = GameObject.FindGameObjectWithTag("GameOver").GetComponent <GameOverScript>();
            go_script.calculateTotalCoins();
        }

        if (buttonName == "Restart")
        {
            GameObject.FindGameObjectWithTag("ButtonCountDown").GetComponent <Animator>().SetBool("isStart", true);
            GameObject.FindGameObjectWithTag("CoinObject").GetComponent <Animator>().SetBool("isStart", true);
            GameObject.FindGameObjectWithTag("ButtonCountDown").GetComponent <Animator>().SetBool("isEnd", false);
            GameObject.FindGameObjectWithTag("CoinObject").GetComponent <Animator>().SetBool("isEnd", false);
            GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> ().activeCoinCanvas();
            //sg.deactiveCanvas();
            restartLevel();
        }

        if (buttonName == "Menu")
        {
            Application.LoadLevel(0);
        }

        if (buttonName == "VideoButton")
        {
            VideoAds gamecontroller = GameObject.FindGameObjectWithTag("GameController").GetComponent <VideoAds>();
            //gamecontroller.loadAd();
        }

        if (buttonName == "RestartLevel")
        {
            Application.LoadLevel("MainScene");
        }

        if (buttonName == "MoveLeft")
        {
            GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().buttonClick("left");

            /*if(isRight)
             * {
             *      isRight = false;
             *      GameObject.FindGameObjectWithTag("Player").GetComponent<PirateMovement>().Flip();
             * }
             * direction = -1;*/
        }

        if (buttonName == "MoveRight")
        {
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().buttonClick("right");
            }

            /*if(!isRight)
             * {
             *      isRight = true;
             *      GameObject.FindGameObjectWithTag("Player").GetComponent<PirateMovement>().Flip();
             * }
             * direction = 1;*/
        }

        if (buttonName == "SeeUp")
        {
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().buttonClick("up");
            }

            /*if(!isRight)
             * {
             *      isRight = true;
             *      GameObject.FindGameObjectWithTag("Player").GetComponent<PirateMovement>().Flip();
             * }
             * direction = 1;*/
        }

        if (buttonName == "Still")
        {
            //direction = 0;
            if (GameObject.FindGameObjectWithTag("Player") != null)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().standStill();
            }
        }

        if (buttonName == "Fire")
        {
            GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerFireScript>().InitiateFire();
        }

        if (buttonName == "Jump" && GameObject.FindGameObjectWithTag("Player") != null)
        {
            if (GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().grounded)
            {
                GameObject.FindGameObjectWithTag("Player").GetComponent <PirateMovement>().isgrounded = false;
                //GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>().AddForce(new Vector2(0f, 900f));
                GameObject.FindGameObjectWithTag("Player").GetComponent <JoystickMovement>().activateJump();
            }
        }
    }