コード例 #1
0
    void OnGUI()
    {
        Event e = Event.current;

        if (e.isKey)
        {
            GetComponents <AudioSource>()[0].Stop();
            GetComponents <AudioSource>()[1].Stop();
            if (StaticGameData.isSoundOn)
            {
                GetComponents <AudioSource>()[1].PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
            }
            interactions++;
            print("Perdu");                                                                                     //Jeu perdu
            print("Interactions : " + interactions + ", KeyCode : " + e.keyCode);
            StaticGameData.isLost = true;
            StartCoroutine(StaticGameData.swapScene());
        }
        if (e.isMouse)
        {
            GetComponents <AudioSource>()[0].Stop();
            GetComponents <AudioSource>()[1].Stop();
            if (StaticGameData.isSoundOn)
            {
                GetComponents <AudioSource>()[1].PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
            }
            interactions++;
            print("Perdu");                                                                                     //Jeu perdu
            print("Interaction : " + interactions + ", Mouse clicked !");
            StaticGameData.isLost = true;
            StartCoroutine(StaticGameData.swapScene());
        }
    }
コード例 #2
0
    void OnGUI()
    {
        if (current_tick_count < 2)
        {
            return;
        }
        Event e = Event.current;

        if (e.isKey && e.type == EventType.KeyUp)
        {
            if (e.keyCode == (KeyCode)lettersToPress[0])
            {
                letter1Pressed = true;
                GameObject.Find("tige1").transform.position += new Vector3(0, 1, 0);
            }
            else if (e.keyCode == (KeyCode)lettersToPress[1])
            {
                letter2Pressed = true;
                GameObject.Find("tige2").transform.position += new Vector3(0, 1, 0);
            }
            else if (e.keyCode == (KeyCode)lettersToPress[2])
            {
                letter3Pressed = true;
                GameObject.Find("tige3").transform.position += new Vector3(0, 1, 0);
            }
            else
            {
                StaticGameData.isLost = true;
                StartCoroutine(StaticGameData.swapScene());
            }
        }
    }
コード例 #3
0
    private void onClickListener(GameObject button)
    {
        if (button.name == "Intruder")
        {
            //Jeu gagne
            StaticGameData.Game.Points++;
            GetComponent <AudioSource>().Stop();
            if (StaticGameData.isSoundOn)
            {
                GetComponent <AudioSource>().PlayOneShot(StaticGameData.winSoundEffect, 1F);
            }
            button.GetComponent <Image>().color = new Color32(0, 255, 0, 80);
        }
        else
        {
            //Jeu perdu
            GetComponent <AudioSource>().Stop();
            if (StaticGameData.isSoundOn)
            {
                GetComponent <AudioSource>().PlayOneShot(StaticGameData.lossSoundEffect, 1F);
            }
            button.GetComponent <Image>().color = new Color32(255, 0, 0, 80);
            StaticGameData.isLost = true;
        }

        StartCoroutine(StaticGameData.swapScene());
    }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        if (interactions > 0)
        {
            failedOverlay.SetActive(true);
        }

        if (timeRemaining > 0)
        {
            timeRemaining -= Time.deltaTime;
            //timeText.text = timeRemaining.ToString();
            print(timeRemaining);
        }
        else if (!hasWon)
        {
            GetComponents <AudioSource>()[0].Stop();
            GetComponents <AudioSource>()[1].Stop();
            if (StaticGameData.isSoundOn)
            {
                GetComponents <AudioSource>()[1].PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
            }
            hasWon = true;
            print("Gagne");                                                                                     //Jeu gagné
            StaticGameData.Game.Points++;
            StartCoroutine(StaticGameData.swapScene());
        }
    }
コード例 #5
0
    public void onClickListener(GameObject button)
    {
        if (!gameIsEnd)
        {
            if (sequenceFase == false)
            {
                resetColors();
                button.GetComponent <Image>().sprite = lightColors[int.Parse(button.name)];
                if (actualSequenceItem == 5)
                {
                    goodEnd();
                    StartCoroutine(StaticGameData.swapScene());
                }

                if (sequence[actualSequenceItem] == int.Parse(button.name))
                {
                    actualSequenceItem++;
                }
                else
                {
                    StaticGameData.isLost = true;
                    badEnd();
                    StartCoroutine(StaticGameData.swapScene());
                }
            }
        }
    }
コード例 #6
0
 // Update is called once per frame
 void Update()
 {
     if (!cm.hasLost)
     {
         tickTimer += Time.deltaTime;
         if (tickTimer > TICK_LENGTH && parts.Count > 0)
         {
             current_tick_count++;
             if (current_tick_count > 2)
             {
                 instructions.SetActive(false);
                 currentPart = Random.Range(0, parts.Count);
                 print(current_tick_count);
                 parts[currentPart].Launch(character, launchSpeed);
                 parts.RemoveAt(currentPart);
             }
             tickTimer = 0;
         }
         else if (parts.Count == 0 && !hasWon)
         {
             hasWon = true;
             AudioSource ads = GetComponent <AudioSource>();
             ads.Stop();
             if (StaticGameData.isSoundOn)
             {
                 ads.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
             }
             GameObject.Find("Character").GetComponent <CharacterMovement>().hasWon = true;
             //Mini-jeu gagné
             //VICTOIRE
             StaticGameData.Game.Points++;
             StartCoroutine(StaticGameData.swapScene());
         }
     }
 }
コード例 #7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(moveUp))
        {
            moveY = speed;
        }
        else if (Input.GetKey(moveDown))
        {
            moveY = -speed;
        }
        else
        {
            moveY = 0;
        }

        if (Input.GetKey(moveRight))
        {
            moveX = speed;
        }
        else if (Input.GetKey(moveLeft))
        {
            moveX = -speed;
        }
        else
        {
            moveX = 0;
        }


        if ((moveX == 0 || moveY == 0))
        {
            rigBody.velocity = new Vector2(moveX, moveY);
        }
        else
        {
            rigBody.velocity = new Vector2(0, 0);
        }


        if (timeRemaining > 0)
        {
            timeRemaining -= Time.deltaTime;
        }
        else if (!hasLost)
        {
            hasLost = true;
            ads1.Stop();
            if (StaticGameData.isSoundOn)
            {
                ads1.PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
            }
            StaticGameData.isLost = true;
            StartCoroutine(StaticGameData.swapScene());
        }


        if (hasWon)
        {
        }
    }
コード例 #8
0
 void Update()
 {
     if (letter1Pressed & letter2Pressed && letter3Pressed && !hasWon)
     {
         hasWon = true;
         AudioSource ads = GetComponent <AudioSource>();
         ads.Stop();
         if (StaticGameData.isSoundOn)
         {
             ads.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
         }
         StaticGameData.Game.Points++;
         StartCoroutine(StaticGameData.swapScene());
     }
     tickTimer += Time.deltaTime;
     if (tickTimer > TICK_LENGTH)
     {
         current_tick_count++;
         if (current_tick_count == 2)
         {
             for (int i = 0; i < 3; i++)
             {
                 GameObject.Find("Canvas/Letter" + (i + 1)).GetComponent <Text>().text = "" + (char)lettersToPress[i];
             }
             GameObject.Find("Canvas/Instructions").GetComponent <Text>().text = "";
         }
         if (current_tick_count >= countDownLength)
         {
             StaticGameData.isLost = true;
             StartCoroutine(StaticGameData.swapScene());
         }
         tickTimer = 0;
     }
 }
コード例 #9
0
    public void onClickReplay()
    {
        StaticGameData.isLost      = false;
        StaticGameData.Game.Points = 0;

        StaticGameData.Game = StaticGameData.getNewGame();

        UnityEngine.SceneManagement.SceneManager.LoadScene("LoadingScreen");
        UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync("EndingScreen");
    }
コード例 #10
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        hasArrived = true;
        AudioSource audioSource = GameObject.Find("GameController").GetComponent <AudioSource>();

        audioSource.Stop();
        if (StaticGameData.isSoundOn)
        {
            audioSource.PlayOneShot(StaticGameData.winSoundEffect, 1F);
        }
        StaticGameData.Game.Points++;
        StartCoroutine(StaticGameData.swapScene());
    }
コード例 #11
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.name == "End" && !hasWon)
     {
         hasWon = true;
         ads1.Stop();
         if (StaticGameData.isSoundOn)
         {
             ads1.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
         }
         StaticGameData.Game.Points++;
         StartCoroutine(StaticGameData.swapScene());
     }
 }
コード例 #12
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (!hasLost && !hasWon)
     {
         AudioSource ads = GameObject.Find("GameController").GetComponent <AudioSource>();
         ads.Stop();
         if (StaticGameData.isSoundOn)
         {
             ads.PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
         }
         hasLost = true;
         StaticGameData.isLost = true;
         StartCoroutine(StaticGameData.swapScene());
     }
 }
コード例 #13
0
    void Start()
    {
        if (StaticGameData.isMusicOn)
        {
            GetComponent <AudioSource>().volume = 0.775f;
        }
        else
        {
            GetComponent <AudioSource>().volume = 0;
        }
        Screen.fullScreen              = true;
        StaticGameData.Game            = StaticGameData.getNewGame();
        StaticGameData.winSoundEffect  = this.winSoundEffect;
        StaticGameData.lossSoundEffect = this.lossSoundEffect;

        StaticGameData.saveHighScore();
    }
コード例 #14
0
    // Update is called once per frame
    void Update()
    {
        if (characterScript.hasArrived)
        {
            timerIsRunning = false;
        }
        if (timerIsRunning && !characterScript.hasArrived)
        {
            //Charachter's movement
            if (rightWasPressed && leftWasPressed)
            {
                character.transform.position = new Vector3(character.transform.position.x + 0.2f, character.transform.position.y);

                rightWasPressed = false;
                leftWasPressed  = false;
            }
        }

        //Timer
        if (timerIsRunning)
        {
            if (Mathf.Round(countDownLength) > 0)
            {
                countDownLength  -= Time.deltaTime;
                timerDisplay.text = Mathf.Round(countDownLength) + " secondes";
            }
            else if (!hasLost)
            {
                GetComponent <AudioSource>().Stop();
                if (StaticGameData.isSoundOn)
                {
                    GetComponent <AudioSource>().PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
                }
                hasLost = true;
                //IL PERD ICI
                timerIsRunning = false;
                rightArrowUp.SetActive(true);
                rightArrowDown.SetActive(false);
                leftArrowUp.SetActive(true);
                leftArrowDown.SetActive(false);
                StaticGameData.isLost = true;
                StartCoroutine(StaticGameData.swapScene());
            }
        }
    }
コード例 #15
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.name == "PaperBall")
     {
         AudioSource ads = GameObject.Find("GameController").GetComponent <AudioSource>();
         ads.Stop();
         if (StaticGameData.isSoundOn)
         {
             ads.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
         }
         print("victoire");
         //La balle est rentrée = victoire
         //IL GAGNE ICI
         StaticGameData.Game.Points++;
         StartCoroutine(StaticGameData.swapScene());
         ballEntered = true;
     }
 }
コード例 #16
0
    void OnGUI()
    {
        if (hasWon || hasLost)
        {
            return;
        }
        Event e = Event.current;

        if (e.isKey && e.keyCode == KeyCode.DownArrow)
        {
            if (e.type == EventType.KeyDown && lastKeyState == false)
            {
                lastKeyState = true;
                downArrowUp.SetActive(false);
                downArrowDown.SetActive(true);
                pressCount++;
                if (pressCount >= pressCountToWin)
                {
                    hasWon = true;
                    AudioSource ads = GetComponent <AudioSource>();
                    ads.Stop();
                    ads.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
                    StaticGameData.Game.Points++;
                    StartCoroutine(StaticGameData.swapScene());
                }
                columnCount++;
                if (pressCount % 12 == 0)
                {
                    arrowCount++;
                    columnCount = 0;
                }
                pencil.transform.position = new Vector3((-6) + columnCount * 0.5f, 3f - arrowCount * 1.2f, 1.0f);
            }
            else if (e.type == EventType.KeyUp && lastKeyState == true)
            {
                lastKeyState = false;
                downArrowUp.SetActive(true);
                downArrowDown.SetActive(false);
            }
        }
    }
コード例 #17
0
 // Update is called once per frame
 void Update()
 {
     if (timerIsRunning && ballEnters.ballEntered == false)
     {
         //Aim rotation
         if (isAiming)
         {
             if (rotationSens)
             {
                 aimIndicator.transform.Rotate(new Vector3(0, 0, rotationSpeed * Time.deltaTime * 10));
             }
             else
             {
                 aimIndicator.transform.Rotate(new Vector3(0, 0, -rotationSpeed * Time.deltaTime * 10));
             }
             int angle = Mathf.RoundToInt(aimIndicator.transform.rotation.eulerAngles.z);
             if (angle <= 270)
             {
                 rotationSens = !rotationSens;
             }
         }
         //Timer
         if (Mathf.Round(countDownLength) > 0)
         {
             countDownLength  -= Time.deltaTime;
             timerDisplay.text = Mathf.Round(countDownLength) + " secondes";
         }
         else if (!hasLost)
         {
             hasLost = true;
             print("lose");
             GetComponent <AudioSource>().Stop();
             GetComponent <AudioSource>().PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
             //FIN DU TIMER = DEFAITE
             //ICI IL PERD
             StaticGameData.isLost = true;
             StartCoroutine(StaticGameData.swapScene());
             timerIsRunning = false;
         }
     }
 }
コード例 #18
0
 // Update is called once per frame
 void Update()
 {
     if (hasWon || hasLost)
     {
         return;
     }
     countDownLength  -= Time.deltaTime;
     timerDisplay.text = Mathf.Round(countDownLength) + " secondes";
     if (countDownLength < 0)
     {
         hasLost = true;
         AudioSource ads = GameObject.Find("GameController").GetComponent <AudioSource>();
         ads.Stop();
         if (StaticGameData.isSoundOn)
         {
             ads.PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
         }
         StaticGameData.isLost = true;
         StartCoroutine(StaticGameData.swapScene());
     }
 }
コード例 #19
0
    // Update is called once per frame
    void Update()
    {
        if (!hasWon && !hasLost)
        {
            if (timer < 0)
            {
                hasLost = true;
                print("lose");
                GetComponent <AudioSource>().Stop();
                if (StaticGameData.isSoundOn)
                {
                    GetComponent <AudioSource>().PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
                }
                //FIN DU TIMER = DEFAITE
                //ICI IL PERD
                StaticGameData.isLost = true;
                StartCoroutine(StaticGameData.swapScene());
            }
            else
            {
                timer -= Time.deltaTime;
            }
            if (Input.GetKey(keyD) && position == Up && !Input.GetKey(keyA) && !Input.GetKey(keyS) && !Input.GetKey(keyW))
            {
                screwdriver.Play();
                rotationEnd += 100;
                print("D");
                position = Right;
                ChangeSprite(3);
            }

            if (Input.GetKey(keyS) && position == Right && !Input.GetKey(keyA) && !Input.GetKey(keyD) && !Input.GetKey(keyW))
            {
                screwdriver.Play();
                rotationEnd += 100;
                print("S");
                position = Down;
                ChangeSprite(4);
            }

            if (Input.GetKey(keyA) && position == Down && !Input.GetKey(keyS) && !Input.GetKey(keyW) && !Input.GetKey(keyD))
            {
                screwdriver.Play();
                rotationEnd += 100;
                print("A");
                position = Left;
                ChangeSprite(1);
            }

            if (Input.GetKey(keyW) && position == Left && !Input.GetKey(keyA) && !Input.GetKey(keyS) && !Input.GetKey(keyD))
            {
                screwdriver.Play();
                rotationEnd += 100;
                print("W");
                position = Up;
                ChangeSprite(2);
            }

            if (rotation < rotationEnd)
            {
                timeConst += Time.deltaTime;
                if (timeConst > incrementTime && !hasWon)
                {
                    float rotationAmount = 500 * Time.deltaTime;
                    screw.transform.Rotate(0f, 0f, -rotationAmount);
                    rotation += rotationAmount;
                    timeConst = 0.0f;
                }
            }
        }
        if (rotation >= 1000 && !hasWon)
        {
            music.Stop();
            if (StaticGameData.isSoundOn)
            {
                music.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
            }
            hasWon = true;
            StaticGameData.Game.Points++;
            StartCoroutine(StaticGameData.swapScene());
        }
    }
コード例 #20
0
    // Update is called once per frame
    void Update()
    {
        if (!hasWon && !hasLost)
        {
            if (timer < 0 && !hasLost)
            {
                hasLost = true;
                ads.Stop();
                if (StaticGameData.isSoundOn)
                {
                    ads.PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);                                                                                                              //Perdu
                }
                StaticGameData.isLost = true;
                StartCoroutine(StaticGameData.swapScene());
            }
            else
            {
                timer -= Time.deltaTime;
            }

            if (Input.GetKey(space) && !hasWon)
            {
                hand.transform.Rotate(0f, 0f, 0f);
                if (rotation > (-green) && rotation < green)
                {
                    hasWon = true;
                    ads.Stop();
                    if (StaticGameData.isSoundOn)
                    {
                        ads.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
                    }
                    StaticGameData.Game.Points++;
                    StartCoroutine(StaticGameData.swapScene());
                }
                else
                {
                    hasLost = true;
                    ads.Stop();
                    if (StaticGameData.isSoundOn)
                    {
                        ads.PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);                                                                                                               //Perdu
                    }
                    StaticGameData.isLost = true;
                    StartCoroutine(StaticGameData.swapScene());
                }
            }
            else if (!hasWon)
            {
                if (rightToLeft)
                {
                    float rotationAmount = speed * Time.deltaTime;
                    hand.transform.Rotate(0f, 0f, -rotationAmount);
                    rotation -= rotationAmount;
                    if (rotation < -90)
                    {
                        rightToLeft = false;
                    }
                }
                else
                {
                    float rotationAmount = speed * Time.deltaTime;
                    hand.transform.Rotate(0f, 0f, rotationAmount);
                    rotation += rotationAmount;
                    if (rotation > 90)
                    {
                        rightToLeft = true;
                    }
                }
            }
        }
    }
コード例 #21
0
 // Start is called before the first frame update
 void Start()
 {
     StaticGameData.saveHighScore();
     GameObject.Find("Score").GetComponent <Text>().text     = "" + StaticGameData.Game.Points;
     GameObject.Find("HighScore").GetComponent <Text>().text = "" + StaticGameData.getHighScore();
 }
コード例 #22
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(moveUp))
        {
            moveY = speed;
        }
        else if (Input.GetKey(moveDown))
        {
            moveY = -speed;
        }
        else
        {
            moveY = 0;
        }

        if (Input.GetKey(moveRight))
        {
            moveX = speed;
        }
        else if (Input.GetKey(moveLeft))
        {
            moveX = -speed;
        }
        else
        {
            moveX = 0;
        }
        if ((moveX == 0 || moveY == 0) && !collision.borderCollision)
        {
            rigBody.velocity = new Vector2(moveX, moveY);
        }
        else
        {
            rigBody.velocity = new Vector2(0, 0);
            if (collision.borderCollision)
            {
                perdu = true;
            }
        }

        if (moveX == 0 && moveY == 0 && isInTolerance && !perdu && !hasWon)
        {
            ads2.Stop();
            if (StaticGameData.isSoundOn)
            {
                ads2.PlayOneShot(StaticGameData.winSoundEffect, 0.5f);
            }
            hasWon = true;
            print("Gagne");                                                                                         //Gagné
            StaticGameData.Game.Points++;
            StartCoroutine(StaticGameData.swapScene());
        }


        if (timeRemaining > 0)
        {
            timeRemaining -= Time.deltaTime;
        }
        else
        {
            perdu = true;
        }

        if (isTooFar)
        {
            perdu = true;
        }

        if (perdu)
        {
            ads2.Stop();
            if (StaticGameData.isSoundOn)
            {
                ads2.PlayOneShot(StaticGameData.lossSoundEffect, 0.5f);
            }
            print("Perdu");                                                                                         //Perdu
            StaticGameData.isLost = true;
            StartCoroutine(StaticGameData.swapScene());
        }
    }