Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (moving == false)
        {
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                if (map.MapCollision[x - 1, y] != 1)
                {
                    if (myanim.AnimState == 0)
                    {
                        myanim.StartRunning();
                        x               -= 1;
                        movevector.x    -= 1;
                        moving           = true;
                        myrenderer.flipX = true;
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                if (map.MapCollision[x + 1, y] != 1)
                {
                    if (myanim.AnimState == 0)
                    {
                        myanim.StartRunning();
                        x               += 1;
                        movevector.x    += 1;
                        moving           = true;
                        myrenderer.flipX = false;
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                if (map.MapCollision[x, y + 1] != 1)
                {
                    if (myanim.AnimState == 0)
                    {
                        myanim.StartRunning();
                        y            += 1;
                        movevector.y += 1;
                        moving        = true;
                    }
                }
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                if (map.MapCollision[x, y - 1] != 1)
                {
                    if (myanim.AnimState == 0)
                    {
                        myanim.StartRunning();
                        y            -= 1;
                        movevector.y -= 1;
                        moving        = true;
                    }
                }
            }
        }

        if (moving == true)
        {
            transform.position = Vector3.MoveTowards(transform.position, movevector, 0.5f * Time.deltaTime * speed);
            if (Vector3.Distance(transform.position, movevector) < 0.01f)
            {
                transform.position = movevector;
                moving             = false;
                myanim.StartIdle();
            }
        }
    }
Пример #2
0
    void Update()
    {
        if (StartFish == false)
        {
            if (Input.GetMouseButtonDown(0))
            {
                endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                if (endPos.x < transform.position.x)
                {
                    myrenderer.flipX = true;
                }
                else
                {
                    myrenderer.flipX = false;
                }



                if ((endPos.y < 4.5f || endPos.x < 4.5f) && (transform.position.x <= 5.5 || transform.position.y <= 5.5))
                {
                    if (myanim.AnimState == 0)
                    {
                        myanim.StartFish();

                        TheHook.transform.position = lineRenderers.GetPosition(1);
                        offest = Vector3.Distance(transform.position + startPos, endPos);
                        lineRenderers.enabled = true;

                        endPos.y += offest;
                        startY    = endPos.y;
                        timeStart = 0;
                        StartFish = true;
                        throwing  = true;
                        TheHook.gameObject.SetActive(true);
                    }
                }
            }
        }
        else
        {
            if (throwing == true)
            {
                timeStart += Time.deltaTime * speed;

                if (timeStart < offest)
                {
                    endPos.y = startY - timeStart;
                }



                for (int i = 0; i < 1; i++)
                {
                    lineRenderers.SetPosition(0, transform.position + startPos);
                    lineRenderers.SetPosition(1, Vector3.MoveTowards(lineRenderers.GetPosition(1), endPos, 0.5f * Time.deltaTime * speed));
                    TheHook.transform.position = lineRenderers.GetPosition(1);


                    //   lineRenderers.SetPosition(i, new Vector3(i * 0.5f, Mathf.Sin(i + t), 0.0f));
                }

                if (Vector3.Distance(lineRenderers.GetPosition(1), endPos) < 0.01f && timeStart >= offest)
                {
                    endPos         = startPos + transform.position;
                    throwing       = false;
                    hook.enableHit = true;
                }
            }
            else
            {
                lineRenderers.SetPosition(0, transform.position + startPos);
                lineRenderers.SetPosition(1, Vector3.MoveTowards(lineRenderers.GetPosition(1), endPos, 0.5f * Time.deltaTime * speed / 4));
                TheHook.transform.position = lineRenderers.GetPosition(1);

                if (Vector3.Distance(lineRenderers.GetPosition(1), endPos) < 0.01f)
                {
                    StartFish = false;
                    TheHook.gameObject.SetActive(false);

                    for (int i = 0; i < hook.debree.Count; i++)
                    {
                        if (hook.debree[i].myType == DebreeType.Wood)
                        {
                            currency.addWood(1);
                        }
                        else
                        {
                            currency.addLeaves(1);
                        }
                    }
                    for (int i = 0; i < hook.debree.Count; i++)
                    {
                        Destroy(hook.debree[i].gameObject);
                    }
                    hook.debree.Clear();

                    hook.enableHit        = false;
                    lineRenderers.enabled = false;
                    myanim.StartIdle();
                }
            }
        }
    }