Exemple #1
0
    // TODO: Take in account of invincibility
    public void TakeDamage(int damage, float bloodScale)
    {
        if (!isInvincible)
        {
            isInvincible   = true;
            currentHealth -= damage;

            // Play sound
            if (hurtSounds != null)
            {
                AudioSource.PlayClipAtPoint(hurtSounds[Random.Range(0, hurtSounds.Length)], Camera.main.transform.position, .2f);
            }

            // Check for health. Splatter blood and shake camera for juiciness
            if (currentHealth <= 0)
            {
                Death();
                SplatterBlood(bloodScale * 1.7f);
            }
            else
            {
                SplatterBlood(bloodScale);
            }
            shake.Shake(.1f, .15f);
        }
    }
    void  OnMouseUp()
    {
        if (Time.timeScale != 0)
        {
            Cursor.visible       = true;
            rotatePuzzel.enabled = true;
            dragging             = false;
            if (Input.GetMouseButtonUp(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                int        layerMask      = 1 << 17;
                int        layerMaskWrong = 1 << 21;
                // if the puzzle piece is placed correctly.
                if (Physics.Raycast(ray, out hit, 200, layerMask) && this.transform.tag == "PuzzleObjectCorrect")
                {
                    // Turn on renderer
                    // Count up
                    // Destroy these objects
                    // Spawn new
                    GameObject correctObjectPar = Instantiate(correctParticle, this.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
                    count = 5;
                    rotatePuzzel.textFeedbackPlus();
                    selectScript.playCorrectSound = true;
                    GameObject currentObject = GameObject.Find(spawnerScript.sizeObjects[PuzzelItem.count]);
                    currentObject.GetComponent <Renderer>().enabled = true;
                    currentObject.layer = 18;
                    Destroy(GameObject.FindGameObjectWithTag("PuzzleObjectCorrect"));
                    GameObject[] gos;
                    gos = GameObject.FindGameObjectsWithTag("PuzzleObjectFalse");
                    foreach (GameObject go in gos)
                    {
                        Destroy(go);
                    }
                    spawnerScript.InvSlots.SetActive(true);
                    spawnerScript.infoPanel.SetActive(false);
                    spawnerScript.slotsPanel.SetActive(false);
                    inventory.PiecePlaced(PuzzelItem.count);
                    inventory.OnEnable();
                }
                else if (Physics.Raycast(ray, out hit, 100, layerMaskWrong) && this.transform.tag == "PuzzleObjectCorrect")
                {
                    shakeScript.Shake();
                    count--;
                    CorrectSizeWrongPlace = true;
                    transform.position    = startPosition;
                    if (Scores.Score >= 1)
                    {
                        Scores.Score -= 1;
                        rotatePuzzel.textFeedbackMin();
                        GetComponent <AudioSource>().PlayOneShot(falseAnswerSound);
                    }
                    else
                    {
                        Scores.Score = 0;
                        rotatePuzzel.textFeedbackZero();
                        GetComponent <AudioSource>().PlayOneShot(falseAnswerSound);
                    }
                }
                else if (Physics.Raycast(ray, out hit, 100, layerMask) && this.transform.tag == "PuzzleObjectFalse")
                {
                    shakeScript.Shake();
                    count--;
                    WrongSizeCorrectPlace = true;
                    transform.position    = startPosition;
                    if (Scores.Score >= 1)
                    {
                        Scores.Score -= 1;
                        rotatePuzzel.textFeedbackMin();
                        GetComponent <AudioSource>().PlayOneShot(falseAnswerSound);
                    }
                    else
                    {
                        Scores.Score = 0;
                        rotatePuzzel.textFeedbackZero();
                        GetComponent <AudioSource>().PlayOneShot(falseAnswerSound);
                    }
                }
                else if (Physics.Raycast(ray, out hit, 100, layerMaskWrong) && this.transform.tag == "PuzzleObjectFalse")
                {
                    shakeScript.Shake();
                    count--;
                    WrongSizeWrongPlace = true;
                    transform.position  = startPosition;
                    if (Scores.Score >= 1)
                    {
                        Scores.Score -= 1;
                        rotatePuzzel.textFeedbackMin();
                        GetComponent <AudioSource>().PlayOneShot(falseAnswerSound);
                    }
                    else
                    {
                        Scores.Score = 0;
                        rotatePuzzel.textFeedbackZero();
                        GetComponent <AudioSource>().PlayOneShot(falseAnswerSound);
                    }
                }
                else
                {
                    transform.position = startPosition;
                }
            }
            if (count <= 0)
            {
                showInfoFind = true;
                GameObject cObject = GameObject.Find(spawnerScript.sizeObjects[PuzzelItem.count]);
                cObject.GetComponent <Renderer>().enabled = true;
                cObject.layer = 18;
                Destroy(GameObject.FindGameObjectWithTag("PuzzleObjectCorrect"));
                GameObject[] falseObjects;
                falseObjects = GameObject.FindGameObjectsWithTag("PuzzleObjectFalse");
                foreach (GameObject go in falseObjects)
                {
                    Destroy(go);
                }
                PuzzelItem.count++;
//				spawnerScript.SpawnObjects();
                count = 5;
            }
        }
    }
 public void ShakingCamera(bool state)
 {
     cameraShaking.Shake(state);
 }