Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Idle"))
        {
            gameObject.GetComponent <Animator>().SetBool("Dissapoint", false);
            //OriginalTexture();
            badFood = false;
            OriginalTexture();
        }
        if (gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Spit"))
        {
            MistakeTexture();

            if (!badFood && gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime > 0.7f)
            {
                //Shoot bad food out
                GameObject clone;

                clone = (GameObject)Instantiate(food, gameObject.transform.position + new Vector3(-0.6f, 0.5f, 0), new Quaternion(0, 0, 0, 0));
                clone.GetComponent <Food>().speed = 4;
                clone.GetComponent <CapsuleCollider>().enabled = false;
                clone.tag = "Spit";

                badFood = true;
            }
        }
        if (gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Eat"))
        {
            CorrectTexture();
        }

        //if Cat is holding a tone get excited
        if (Cat.GetComponent <CatController>().Held != null)
        {
            gameObject.GetComponent <Animator>().SetBool("Excite", true);
        }

        //If Bird not selected by Cat then be dissapointed, selected one stays excited
        if (Cat.GetComponent <CatController>().Selected != null && Cat.GetComponent <CatController>().Selected.tag == "Bird")
        {
            if (Cat.GetComponent <CatController>().Selected == gameObject)
            {
                gameObject.GetComponent <Animator>().SetBool("Excite", true);
            }
            else
            {
                gameObject.GetComponent <Animator>().SetBool("Dissapoint", true);
                gameObject.GetComponent <Animator>().SetBool("Excite", false);
                DissapointTexture();
            }
        }

        //Check for touch
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended && Application.isMobilePlatform && !GameTimer.paused)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.gameObject == gameObject)
                {
                    //Don't tell cat to move if not holding any food
                    if (Cat.GetComponent <CatController>().holding > 0)
                    {
                        if (Tutorial.isTutorial && Cat.GetComponent <CatController>().Held.GetComponent <Food>().tone != tone)
                        {
                            Sounds.BirdWrong();
                        }
                        else
                        {
                            Cat.GetComponent <CatController>().Selected = gameObject;
                            Cat.GetComponent <CatController>().state    = State.Move;
                        }
                    }
                }
            }
        }

        //Check for mouse click
        if (Input.GetMouseButtonDown(0) && !Application.isMobilePlatform && !GameTimer.paused)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.gameObject == gameObject)
                {
                    //Don't tell cat to move if not holding any food
                    if (Cat.GetComponent <CatController>().holding > 0)
                    {
                        if (Tutorial.isTutorial && Cat.GetComponent <CatController>().Held.GetComponent <Food>().tone != tone)
                        {
                            Sounds.BirdWrong();
                        }
                        else
                        {
                            Cat.GetComponent <CatController>().Selected = gameObject;
                            Cat.GetComponent <CatController>().state    = State.Move;
                        }
                    }
                }
            }
        }

        //Check if held food is inside Bird Collider and this Bird is Selected by the player
        if (Cat.GetComponent <CatController>().holding > 0 && Cat.GetComponent <CatController>().Held != null)
        {
            if (gameObject.GetComponent <Collider>().bounds.Contains(Cat.GetComponent <CatController>().Held.transform.position) && Cat.GetComponent <CatController>().Selected == gameObject)
            {
                ReactToFood(Cat.GetComponent <CatController>().Held.GetComponent <Collider>());
            }
        }
    }