Example #1
0
    public void Slice()
    {
        if (Input.GetKeyDown(KeyCode.Space) && !hasPressed)
        {
            if (Physics.Linecast(transform.position, target.position))
            {
                print("hit");
                //ReturnToPosition();
                failNumber = 0;
                noteSpeed += 0.1f;
                audioSource.PlayOneShot(chop);
                audioSource.pitch += 0.1f;
                food = GameObject.FindGameObjectWithTag("Food");
                food.GetComponent <Renderer>().material.color = new Color(0f, 1f, 0f);
                //Debug.Log("You hit the mark!!");
                foodValue = foodController.totalScore;
                gameManager.scoreText.text = "Score: " + foodController.AddScore(foodValue);

                if (eyebrows.GetComponent <SpriteRenderer>().sprite == angryEyebrows)
                {
                    eyebrows.GetComponent <SpriteRenderer>().sprite = normalEyebrows;
                }
                else
                {
                    eyes.GetComponent <SpriteRenderer>().sprite = happyEyes;
                }
            }
            else
            {
                print("miss");
                audioSource.PlayOneShot(miss);
                audioSource.pitch -= 0.1f;
                //ReturnToPosition();
                failNumber++;
                noteSpeed -= 0.1f;
                foodValue  = foodController.totalScore;
                gameManager.scoreText.text = "Score: " + foodController.SubScore(foodValue);

                if (eyes.GetComponent <SpriteRenderer>().sprite = happyEyes)
                {
                    eyes.GetComponent <SpriteRenderer>().sprite = normalEyes;
                }
                else
                {
                    eyebrows.GetComponent <SpriteRenderer>().sprite = angryEyebrows;
                }
            }

            /*
             *          RaycastHit hit = Physics.Raycast(transform.position, -Vector2.up, 500f);
             *          if (hit.collider.tag == "Food")
             *          {
             *              ReturnToPosition();
             *              failNumber = 0;
             *              noteSpeed += 0.1f;
             *              audioSource.PlayOneShot(chop);
             *              audioSource.pitch += 0.1f;
             *              food = GameObject.FindGameObjectWithTag("Food");
             *              food.GetComponent<Renderer>().material.color = new Color(0f, 1f, 0f);
             *              //Debug.Log("You hit the mark!!");
             *              foodValue = foodController.totalScore;
             *              gameManager.scoreText.text = "Score: " + foodController.AddScore(foodValue);
             *          }
             *          if (hit.collider.tag == null)
             *          {
             *              audioSource.PlayOneShot(miss);
             *              audioSource.pitch -= 0.1f;
             *              ReturnToPosition();
             *              failNumber++;
             *              noteSpeed -= 0.1f;
             *              foodValue = foodController.totalScore;
             *              gameManager.scoreText.text = "Score: " + foodController.SubScore(foodValue);
             *          }
             *          playerRB.AddForce(Vector3.down * sliceSpeed);
             *          //transform.Translate(Vector3.down * sliceSpeed * Time.deltaTime);
             *          hasSliced = true;
             *          hasPressed = true;
             *      }
             */
        }

        /*
         *  public void ReturnToPosition()
         *  {
         *      if (hasSliced)
         *      {
         *          playerRB.AddForce(originalPos * moveSpeed);
         *          //playerRB.MovePosition(originalPos);
         *          //playerRB.transform.Translate(originalPos);
         *          playerRB.velocity = Vector3.zero;
         *          hasPressed = false;
         *      }
         *  }
         */

        /*
         *  public void StopAtOriginalPosition()
         *  {
         *      if (playerRB.position.y >= 5)
         *      {
         *          playerRB.velocity = Vector3.zero;
         *          //Debug.Log("Has made it to original position");
         *      }
         *  }
         */

        /*
         * private void OnCollisionEnter(Collision c)
         * {
         *  if (c.gameObject.CompareTag("Table"))
         *  {
         *      audioSource.PlayOneShot(miss);
         *      audioSource.pitch -= 0.1f;
         *      ReturnToPosition();
         *      failNumber ++;
         *      noteSpeed -= 0.1f;
         *      foodValue = foodController.totalScore;
         *      gameManager.scoreText.text = "Score: " + foodController.SubScore(foodValue);
         *  }
         * }
         */

        /*
         *  private void OnTriggerEnter(Collider c)
         *  {
         *      if(c.gameObject.CompareTag("Food"))
         *      {
         *          ReturnToPosition();
         *          failNumber = 0;
         *          noteSpeed += 0.1f;
         *          audioSource.PlayOneShot(hit);
         *          audioSource.pitch += 0.1f;
         *          food = GameObject.FindGameObjectWithTag("Food");
         *          food.GetComponent<Renderer>().material.color = new Color(0f, 1f, 0f);
         *          //Debug.Log("You hit the mark!!");
         *          foodValue = foodController.totalScore;
         *          gameManager.scoreText.text = "Score: " + foodController.AddScore(foodValue);
         *      }
         *  }
         */
    }