Example #1
0
    private void HandleMoundAction(Collider overlap)
    {
        Mound mound = overlap.GetComponent <Mound>();

        if (mound)
        {
            if (mound.isReadyToHarvest)
            {
                animator.SetTrigger("Action");
                SeedType harvested = mound.GetHarvested();
                Debug.Log(harvested);

                Text scoreUI = GameObject.FindWithTag("Score").GetComponentInChildren <Text>();
                scoreUI.text = (int.Parse(scoreUI.text) + rewards[harvested]).ToString();

                // prevent death
                seedSelector.ResetHealth();
                return;
            }

            if (mound.seedType != SeedType.None && mound.growTime > 0)
            {
                // seed is busy growing
                return;
            }

            SeedType plantedSeed = seedSelector.PlantSeed();
            if (plantedSeed != SeedType.None)
            {
                // plant new seed
                animator.SetTrigger("Action");
                mound.AddSeed(plantedSeed);
            }
        }
    }
Example #2
0
    void Update()
    {
        if (isDying)
        {
            return;
        }

        if (!target)
        {
            target = FindMound();
            if (!target)
            {
                target = player;
            }
        }
        else
        {
            float distance = Vector3.Distance(target.transform.position, transform.position);
            if (distance <= EATING_DISTANCE)
            {
                if (target.tag == "Mound")
                {
                    Mound mound = target.GetComponent <Mound>();
                    if (mound.seedType == SeedType.None)
                    {
                        // mound was empty on arrival
                        animator.ResetTrigger("Eat");
                        target = null;
                        return;
                    }

                    if (eatTime >= END_EAT_TIME)
                    {
                        // eating complete
                        target.GetComponent <Mound>().GetEaten();
                        target  = null;
                        eatTime = 0;
                        animator.ResetTrigger("Eat");
                        animator.SetTrigger("Idle_Left");
                    }
                    else
                    {
                        // continue eating
                        eatTime += Time.deltaTime;
                        animator.SetTrigger("Eat");
                    }
                }
                else
                {
                    // check for new plants before continuing to chase player
                    target = FindMound();
                    animator.ResetTrigger("Eat");
                }
            }
            else
            {
                animator.ResetTrigger("Eat");

                // move towards target
                int dir = target.transform.position.x > transform.position.x ? 1 : -1;
                if (dir > 0)
                {
                    animator.SetTrigger("Idle_Right");
                }
                else
                {
                    animator.SetTrigger("Idle_Left");
                }
                transform.position += new Vector3(dir * speed * Time.deltaTime, 0, 0);
                eatTime             = 0;
            }
        }
    }