Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        var vertical   = Input.GetAxisRaw("Vertical");
        var horizontal = Input.GetAxisRaw("Horizontal");

        // Cannot go Up if not in the water
        if (!m_entity.InWater())
        {
            vertical = Mathf.Clamp(vertical, -1.0f, 0f);
        }

        //Debug.Log("Vertical " + vertical);

        m_entity.SetMoveDirection(new Vector3(horizontal, vertical, 0), true);

        // Grappling hook
        if (Input.GetKeyDown(KeyCode.Mouse1) && PlayerLevel >= 1)
        {
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3 dir3          = mousePosition - transform.position;
            Vector2 dir           = new Vector2(dir3.x, dir3.y).normalized;

            foreach (Transform child in grapplingHookParent)
            {
                Destroy(child.gameObject);
            }

            GameObject hook = Instantiate(grapplingHook, transform.position + (Vector3)dir * 0.3f, Quaternion.identity, grapplingHookParent);
            m_lastHook = hook.GetComponent <GrapplingHook>();
            m_lastHook.SetMoveDirection(dir);
            if (PlayerLevel == 1)
            {
                m_lastHook.SetHookSpeed(level1HookSpeed);
            }
            else if (PlayerLevel >= 2)
            {
                m_lastHook.SetHookSpeed(level2HookSpeed);
            }
        }

        // If a movement key is pressed, delete latched hook
        if (
            Input.GetKey(KeyCode.W) ||
            Input.GetKey(KeyCode.A) ||
            Input.GetKey(KeyCode.S) ||
            Input.GetKey(KeyCode.D) ||
            Input.GetKey(KeyCode.LeftArrow) ||
            Input.GetKey(KeyCode.RightArrow) ||
            Input.GetKey(KeyCode.UpArrow) ||
            Input.GetKey(KeyCode.DownArrow)
            )
        {
            if (m_lastHook != null)
            {
                m_lastHook.DeleteIfLatched();
            }
        }
    }