Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (shovelTimer < 1)
        {
            shovelTimer += Time.deltaTime;
        }

        if (walk)
        {
            anim.Play("Walk");
            transform.Translate((movePos - transform.position).normalized * speed * Time.deltaTime);
            if ((movePos - transform.position).magnitude < 0.1f)
            {
                start = true;
                walk  = false;
                StartCoroutine("Text");
                anim.Play("Idle");
            }
        }

        if (start)
        {
            if (Input.GetMouseButtonDown(0))
            {
                hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 100, LayerMask.GetMask("Water"));
                if (hit)
                {
                    switch (hit.collider.name)
                    {
                    case "Trap":
                        disarm     = true;
                        shovelFill = false;
                        break;

                    case "Shovel":
                        if (shovelTimer >= 1)
                        {
                            shovelFill = true;
                            disarm     = false;
                        }
                        break;

                    case "Background":
                        if (drink)
                        {
                            goDrink = true;
                        }
                        break;
                    }
                }
            }
        }
        if (disarm)
        {
            anim.Play("Walk");
            transform.Translate((trap.position - transform.position).normalized * speed * Time.deltaTime);
            if ((trap.position - transform.position).magnitude <= 0.1f)
            {
                disarm = false;
                anim.Play("Interact");
                gc.PlayCloseTrap();
                trap.GetComponent <Collider2D>().enabled     = false;
                trap.GetComponent <SpriteRenderer>().enabled = false;
            }
        }
        if (shovelFill)
        {
            anim.Play("Walk");
            transform.Translate((shovel.position - transform.position).normalized * speed * Time.deltaTime);
            if ((shovel.position - transform.position).magnitude <= 0.1f)
            {
                shovelFill = false;
                anim.Play("Interact");
                gc.PlayShovel();
                hole.Fill();
                shovelTimer = 0;
            }
        }
        if (goDrink)
        {
            anim.Play("Walk");
            transform.Translate((pond.position - transform.position).normalized * speed * Time.deltaTime);
            if ((pond.position - transform.position).magnitude <= 0.1f)
            {
                goDrink = false;
                start   = false;
                anim.Play("Interact");
                gc.PlayDrink();
                gc.EndDay();
            }
        }
    }